#!/bin/bash thumbnailsconf=${1:-${0##*/}.conf} test -r "$thumbnailsconf" || exit 1 function set_imgsize () { imgsize[${#imgsize[@]}]=$1 imgsize[${#imgsize[@]}]=$2 imgsize[${#imgsize[@]}]=$3 } #set_imgsize 'custom' 1656 1242 set_imgsize 'xxlarge' 1224 918 set_imgsize 'xlarge' 1008 756 set_imgsize 'large' 792 594 set_imgsize 'medium' 576 432 set_imgsize 'small' 432 324 set_imgsize 'xsmall' 240 240 set_imgsize '2small' 144 144 set_imgsize 'thumb' 120 120 eval $(readconf --conf "$thumbnailsconf" -s mysql -s galeries -s path --case-sensitive --array=galerie) for ((g=0; g<${#galerie[@]}; g++)); do sqlcmd="select concat('file=', path, ';rotation=', rotation * 90) from piwigo_images \ where id in ( \ select image_id from piwigo_image_category \ where category_id in ( \ select id from piwigo_categories where name = '${galerie[$g]}' \ ) \ )" for image in $(mysql -N -u $dbuser -p${dbpasswd} $dbname <<< $sqlcmd); do eval "$image" format="" fnNoExt="${file%.*}" fnExt="${file##*.}" fnPath="${file%/*}" mkdir -p $destDir/$fnPath cmd="nice -n20 convert $site/$file -write mpr:image +delete " for ((i=0; i<${#imgsize[@]}; i+=3)); do if ! test -e ${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt; then format+="${imgsize[i]} " cmd+="mpr:image -filter Lanczos -strip -quality 95 -interlace line -sampling-factor 4:2:2 " if test $rotation -ne 0; then cmd+="-rotate -$rotation -orient top-left " fi cmd+="-resize ${imgsize[i+1]}x${imgsize[i+2]} -write ${destDir}/${fnNoExt}-${imgsize[i]:0:2}.$fnExt +delete " fi done cmd=$(sed 's/\s*+delete\s*$//' <<< $cmd) if test -n "$format"; then echo "$site/$file : $format" eval "$(echo -e $cmd)" echo done sleep 30 fi done done