#!/bin/sh # Author : Mathieu Vilaplana # Date : 09/03/2005 #depends: imagemagick, zenity # thanks to coffe #version 0.4 # - check mime type #since v 0.4, solve bug with filename spaces #version 0.6 # - correct bug in filename with spaces # - create a subdirectory to create images #test if a file has been selected if [ $# -eq 0 ]; then zenity --error --title="error" --text="You must select at least 1 file to process" exit 1 fi #========================= # SELECT SIZE DIALOG title="Choose which sizes to scale to" imgsize=`zenity --title "$title" --list --separator=" " --column="size" "160x120" "320x240" "640x480" "800x600" "800x600" "1024x768" ` #if $? != 0, user click on cancel button, so exit if [ "$?" != 0 ] ; then exit fi #user must select a target size imgsize=`echo $imgsize | sed 's/ max//g'` if [ ! "$imgsize" ]; then zenity --error --title="error" --text="select a target size" exit fi #transform 640x480 en 640x640 for convert to respect proportions himgsize=$imgsize val1=`echo "$imgsize" | awk -F'x' '{ print $1 }'` imgsize="${val1}x${val1}" # END SELECT SIZE DIALOG #========================= #Select only images nb_images=0; selection=""; while [ $# -gt 0 ]; do isimage=`file -bi "$1" | grep image | wc -l` if [ $isimage -eq 1 ]; then selection[$nb_images]=$1 let "nb_images++" fi shift done #create directory if not exist and at least one image to process if [ ! -d $himgsize ] && [ "$nb_images" -gt "0" ];then mkdir $himgsize fi n=$nb_images let "n=n-1" (for i in `seq 0 $n`;do picture=${selection[$i]} let "compteur += 1" echo "# Processing image $compteur / $nb_images $picture ..." convert -quality 80 -resize $imgsize "$picture" $himgsize/"$picture" let "progress = compteur*100/nb_images" echo $progress done ) | zenity --progress --auto-close --title="Scaling images" --text="Processing images ..." --percentage=0