Des screenshots avec style - Version 2

Après avoir vu l'effet sympathique, légérement différent du mien, des miniatures des screenshots de WindowsSucks sur ubuntuforums.org, j'ai décidé de l'ajouter à mon script.

Je vous propose donc une seconde version de mon script où j'en ai profité pour améliorer le traitement des options (le second effet pouvant être choisi ainsi).

#!/bin/bash
# Screenshot Script
# Author : Hells_Dark
# Homepage : http://breves.hellsdark.homelinux.net
# Required :
# scrot
# imagemagick
#
# Usage : shot [ Options ... ] [legend]
#
# Options :
#         -d      Set the destination directory to 
#         -l                 Thumbnail with legend
#         -w          Set the thumbnail width to 
#         -t           Define the thumbnail effect to  (1, 2 or 3)
#         -s time            Set the delay before shot to 

#
# Usage Example :  shot -l -w300 -t2 -s3 "Awesome !"


## Colorisation ##

  #Colors

  blue="\033[1;34m"
  green="\033[1;32m"

  #Style

  gras="\033[00m"

  #Default

  end="\033[0m"

## Configuration ##

# thumbnail name

prefix=''
sufix='s'
thumbnail_name=$prefix$(date +%d%m%y )$sufix.png

# thumbnail width

thumbnail_height=''
thumbnail_width='300'

# screenshot name

name=$(date +%d%m%y ).png

# Legend text

thumbnail_legend="HellsDark Desktop - $(date +%d/%m/%y )"

# Defaut legend presence

caption="no"

# Default path

path="$HOME/"

# Default Waiting time before screenshot

delay=0

# Default effect

type=1

## Options

function help {
    echo
    echo -e "${green}Usage$end : $0 [ Options ... ] [legend]\n"
    echo -e "${green}Options$end :"
    echo -e "\t -d ${blue}directory$end     Set the destination directory to ${blue}directory$end"
    echo -e "\t -l               Thumbnail with legend"
    echo -e "\t -w ${blue}width$end         Set the thumbnail width to ${blue}width$end"
    echo -e "\t -t ${blue}type$end          Define the thumbnail effect to ${blue}type$end (1, 2 or 3)\n"
    echo -e "\t -s ${blue}time$end          Set the delay before shot to ${blue}time$end (seconds)\n"
    echo -e "${green}Examples$end :"
    echo -e "\t shot -t2 -l -s5 -d /home/myuser/"
    echo -e "\t Creates a screenshot in the /home/myuser directory 
         and generates a thumbnail with a type effect 2, a legend
         and wait for 2s before taking the screenshot."
    echo
}

while getopts hd:lw:t:s: option
  do
    case $option in
    h)
      help
      exit 0
    ;;
    d)
      directory=$OPTARG
      if [ -a $directory ]; then
       path="$directory/"
      else
        echo "The directory $directory does not exist." 1>&2
        exit 2
      fi
    ;;
    l)
      caption="yes"
    ;;
    w)
      if echo $OPTARG | grep -q -E '^[0-9]*[.]?[0-9]*$';then
        thumbnail_width=$OPTARG
      else
        echo "$OPTARG is not a valid width." 1>&2
        exit 3
      fi
    ;;
    t)
      if (( $OPTARG > 0 && $OPTARG <4 ));then
        type=$OPTARG
      fi
    ;;
    s)
      if echo $OPTARG | grep -q -E '^[0-9]+$';then
        delay=$OPTARG
      else
        echo "$OPTARG is not a valid delay." 1>&2
        exit 3
      fi
    ;;
    ?)
      help
      exit 1
    ;;
  esac
done
shift $(($OPTIND-1))


## Screenshot and thumbnail creation ##

if (( $delay != 0 ));then
  echo
  echo -en $green' + Wait : '$end
  for i in $(seq $delay -1 1);do
    echo -n " $i.."
    sleep 1
  done
  echo
fi

echo
echo -e $blue' == Screenshot in progress =='$end
scrot "$path$name"
echo
echo " + saving as $path$name"
echo -e $green' + done'$end
echo

echo -e $blue' == Thumbnail creation =='$end
echo

echo ' + Resizing in progress'
convert -resize "$thumbnail_width"x"$thumbnail_height" "$path$name" "$path$thumbnail_name"

if [ $caption = "yes" ]; then
  echo ' + Adding caption in progress'

  # Getting actual thumbnail width..

  w=$(identify -format %w "$path$thumbnail_name")

  if [ "$1" != "" ];then
    thumbnail_legend=$1
  fi

  # Adding legend..

  convert -background '#0004' -fill white -gravity center -size ${w}x15 \
    caption:"$thumbnail_legend" \
    +size $path$thumbnail_name +swap -gravity south -composite  $path$thumbnail_name
fi

echo ' + Adding Borders & Shadows in progress'

if (( $type == 1 ));then # Type 1

  convert -page +4+4  "$path$thumbnail_name" \
  -bordercolor grey80  -border 1 \
  -bordercolor white  -border 1 \
  -bordercolor grey40  -border 1 \
  -background  black  \( +clone -shadow 70x2+2+2 \) +swap \
  -background  black  \( +clone -shadow 70x2-2-2 \) +swap \
  -background  transparent -flatten \
  -depth 32 "$path$thumbnail_name"
  
elif (( $type == 2 ));then # Type 2

  rot=0
  let "rot = $RANDOM % 20 - 10"
  convert "$path$thumbnail_name" \
  -bordercolor white  -border 6 \
  -bordercolor grey60 -border 1 \
  -background  none   -rotate $rot \
  -background  black  \( +clone -shadow 60x4+4+4 \) +swap \
  -background  transparent   -flatten \
  -depth 8  -quality 95   "$path$thumbnail_name"
  
elif (( $type == 3 ));then

  # small border

  convert -page +4+4  "$path$thumbnail_name" \
  -bordercolor "#333333"  -border 1 \
  -depth 32 "$path$thumbnail_name"
  
  # rounded borders

  w=$(identify -format %w "$path$thumbnail_name")
  h=$(identify -format %h "$path$thumbnail_name")
  convert -size ${w}x${h} xc:none -fill white \
  -draw "roundRectangle 0,0 $w,$h 5,5" "$path$thumbnail_name" \
  -compose SrcIn \
  -composite "$path$thumbnail_name"
  
  # shadows

  w=$((w+4))
  h=$((h+4))
  convert -page ${w}x${h}+4+4  "$path$thumbnail_name" \
  -background  "#333333"  \( +clone -shadow 70x2+2+2 \) +swap \
  -background  "#333333"  \( +clone -shadow 70x2-3-2 \) +swap \
  -background  transparent -flatten \
  -depth 32 "$path$thumbnail_name"

fi

# End message

echo -e $green' + done'$end
echo

exit 0

Enjoy !

02/04/08, 00:00

Commentaires

Commentaires désactivés.