#!/bin/bash # use newer version of imagick export PATH=/home/www-lp/workspaces/bin:${PATH} MIN_WIDTH=500 MIN_HEIGHT=500 MAX_WIDTH=3000 MAX_HEIGHT=3000 SRC_HOME=/home/www-lp/www/images/image OUTPUT_HOME=/home/www-lp/www/images-${MIN_WIDTH}x${MIN_HEIGHT}--${MAX_WIDTH}x${MAX_HEIGHT}/image smartresize() { filename="$1" geometry="$2" output_dir="$3" mogrify -path "$output_dir" -filter Triangle -define filter:support=2 -thumbnail $geometry -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB "$filename" } total=$(cd $SRC_HOME; find . -type f | wc -l) count=0 IFS=$(echo -en "\n\b") for f in $(cd $SRC_HOME; find . -type f) do basename_filename=$(basename $f) filename="${SRC_HOME}/$f" wxh=$(identify -format "%[fx:w]x%[fx:h]" "$filename" 2>/dev/null) if [ ! -z "$wxh" ] then output_dir=$(dirname "${OUTPUT_HOME}/$f") [ -d $output_dir ] || mkdir -p $output_dir crc=$(cat $filename | sum) crc_file=$output_dir/.${basename_filename}.original-crc if [ "$crc" != "$(cat $crc_file 2>/dev/null)" ] # crc of original file has changed then w=${wxh/x*/} h=${wxh/*x/} if [ $w -gt ${MAX_WIDTH} -o $h -gt ${MAX_HEIGHT} ] then smartresize "$filename" ${MAX_WIDTH}x${MAX_HEIGHT} "$output_dir" elif [ $w -lt ${MIN_WIDTH} -o $h -lt ${MIN_HEIGHT} ] then # geometry option flag '^' used to resize the image based on the smallest fitting dimension smartresize "$filename" ${MIN_WIDTH}x${MIN_HEIGHT}^ "$output_dir" else [ -f $output_dir/$f ] && /bin/rm -f $output_dir/$f ln "$filename" "$output_dir" fi echo $crc > $crc_file # store sum of original picture to avoid unnecessary reprocessing of file fi fi count=$((count+1)) # python -c "print '%02.02f%%' % (float($count)/$total*100)" done echo Done