0 Members and 1 Guest are viewing this topic.
#!/bin/bashcase $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;;esacexit 0##@ Maintainer: eulenreich _@_ gmx _._ de