I usually resize and watermakr imaghes on the console, but every step savesd the jpg and I think it would be wise only to save at the end to have better quality.
So I would like to have a script that does the following:
1. Change JPG to jpg
for file in *.JPG; do mv $file ${file%.*}.jpg; done
2. Resize:
for i in *.jpg; do convert -resize 1200x1200 -quality 80 $i `basename $i .jpg`-.jpg; done
3. Add watermark 1:
for i in *.jpg; do composite -gravity SouthEast /path/to/watermark1.png $i `basename $i .jpg`-water.jpg; done
4. Add Watermark 2
for i in *.jpg; do composite -gravity Southwest /path/to/watermark2.png $i `basename $i .jpg`-water.jpg; done
As a bonus, for the motivated, I would like it to do it on subfolders and save everything somewhere else (to not overwirte the original files). But thats not that important (would be nice)
Ralul once made me a cool script to resize a folder with all subfolfers .
Maybe it helps.
#!/bin/bash
case $1 in
-e|--edit) # this script #@
[ -f /usr/bin/mcedit ] &&MyEditor=/usr/bin/mcedit ||MyEditor=/usr/bin/nano
exec $MyEditor $0
;;
-c|--convert) # pictures #@
#@
# Variables to edit: #@
#
# ExcludeNames single quotes!
export ExcludeNames='*junk* doubl*' #@
export MaxDepth="8" #@
export SaveTo=~/optimizedPictures #@ "" for saving to workdir
export OldRemove="N" #@
export UseExif="N" #@
export ConvertApp="/usr/bin/convert" #@
export Action="-resize 1920x -quality 98" #@
##@
##@ Examples:
##@ resize to your monitor hight and keep aspect ratio and good quality:
##@ export Action="-resize x1024 -compress JPEG2000 -quality 98"
##@ resize to your monitor width keeping aspect ratio:
##@ export Action="-resize 1280x -quality 64"
##@ delete 240 pixel of both sides from 1920x1080 to get to 4/3 ratio:
##@ export Action="-crop 1440x1080+240+0"
##@ two Actions: resize wide image to 1920 and crop to 4/3 format
##@ export Action="-resize 1920x -crop 1400x1050+260+15"
##@
if [ "$SaveTo" = "" ] ; then
export SaveTo="_$( date +%Y%m%d%H%M ).jpg"
export externSave="0"
else
[ -d "$SaveTo" ] || mkdir -p "$SaveTo" || exit 1
SaveTo="$( readlink -e $SaveTo )" # if link then dereference
export externSave="1"
fi
if [ "$2" != "" ] ; then
cd "$2" || exit 1 # workdir was given!
fi
cd "$( readlink -e "$PWD" )" # if link then dereference
export startDir="$( dirname $PWD )"
[ "${SaveTo}" != "${SaveTo#$PWD}" ] \
&& echo "Error - workDir contains SaveTo: $SaveTo" \
&& exit 1
echo " "
echo " ConvertApp Action: $ConvertApp $Action "
echo " in: $PWD "
echo " MaxDepth: $MaxDepth "
echo " ExcludeNames: $ExcludeNames"
echo " SaveTo: $SaveTo "
echo " OldRemove: $OldRemove "
echo " UseExif: $UseExif "
read -t 44 -p " convert pictures? [y|n] " doit
[ "$doit" != "y" ] && echo " --noAction " && exit 0
echo ". "
find . -maxdepth $MaxDepth -type d -execdir "$0" convertWorker '{}' ';'
[ "$externSave" = "1" ] && echo -n -e "\n converted pictures in: $SaveTo \n"
;;
########################################
convertWorker)
# we must cd into
cd "$2" || exit 1
# This script does in subdirs: #@
for i in *.[Jj][Pp][Ee][Gg] ; do [ -f "$i" ] && mv "$i" "${i%.[Jj][Pp][Ee][Gg]}.jpg"; done
for i in *.J[Pp][Gg] ; do [ -f "$i" ] && mv "$i" "${i%.J[Pp][Gg]}.jpg"; done
# clean special letters in filenames
#for i in *{\+,\&,\(,\[,\ }*.jpg ; do
# [ -f "$i" ] && mv "$i" "$( echo $i|tr '()[]&+[:blank:]' '----___' )"
#done
# SaveTo ends with a slash - otherwise it is a tempName
if [ "$externSave" = "0" ] ; then
# datetime tempname without trailing slash
actual="${SaveTo}" # actual for the tmp_filename
else
for i in * ; do
if [ -f $i ] ; then # if there is a file make SaveTo/thisDirName/
m=${PWD#$startDir}
actual="${SaveTo}/${m#/}/"
mkdir -p "${actual}" || exit 4
break
fi
done
fi
echo -n -e "\n $PWD \n"
for i in *.jpg ; do # convert pictures #@
[ -f "$i" ] || continue 1 # if no file for returns *.jpg
echo -n " $i "
for j in $ExcludeNames ; do # but exclude some files #@
if [ "$i" = "$j" ] ; then
echo -n "--exlcuded "
continue 2
fi
done
if [ "$UseExif" = "Y" -o "$UseExif" = "y" ] ; then
exif -m "$i" >/dev/null 2>&1
if (( $? > 0 )) ; then
echo "-NoExif-------------------------- "
continue 1
fi
if (( ${xnew} < $( exif -m "$i"|sed -e '/PixelXDimension/s/PixelXDimension.//p' -e 'd' ) )) ; then
exif_seem_to_indicate_size=good
else
echo "-WasTooLittle----------------------"
continue 1
fi
fi
[ "$externSave" = "1" ] && s="${actual}$i" || s="${i%.jpg}${actual}"
$ConvertApp "$i" $Action "$s"
if [ "$?" = "0" -a -f "$i" -a -f "$s" ] ; then
if [ "$externSave" = "0" ] ; then
if [ "$OldRemove" = "Y" -o "$OldRemove" = "y" ] ; then
rm "$i" && mv "$s" "$i"
fi
fi
fi
done
echo " "
;;
*)
echo -n -e " Help: \n $( basename $0 ) -e|-c [dir] \n \n"
# print Helplines - containing a comment # followed by @
grep -e '\#\@' $0 | sed -e 's/\#\@//'
exit 0
;;
esac
exit 0
##@ Maintainer: eulenreich _@_ gmx _._ de
Thanks for your help! Such a script would be really cool and a help to every photographer!
Edit: When I think about it, it would be nice to rename the files i a first step by defining a name like "monday" with the result, that the photos will have filenames like "monday-001.jpg, monday-002.jpg, monday-003.jpg" etc