#!/bin/sh ROOT=../www SRC=../www/img SIZE=500 # transform path to /img/*/.thumb/ pathtrans() { filename=$(echo $1 | awk -F/ '{print $NF}') filename=$(echo ${filename} | awk 'BEGIN{FS=OFS="."}{NF--; print $0}') transform=$(echo $1 | awk 'BEGIN{FS=OFS="/"}{NF--; print $0}') if [ ! -d ${transform}/.thumb ]; then mkdir ${transform}/.thumb/ fi transform=${transform}/.thumb/${filename}.png echo ${transform} } # generate thumbnails in /img/*/.thumb/ resize() { output=$(pathtrans $1) if echo $1 | grep .gif > /dev/null; then return fi if [ ! -f ${output} ]; then echo "generating thumbnail for $1" convert $1 -strip -auto-orient -resize ${SIZE} -dither FloydSteinberg -colors 16 ${output} fi } if [ -z $1 ]; then echo "usage: $0 [build|clean]" else case $1 in "build") echo "creating new thumbnails" for x in $(find ${SRC}/*/*); do resize $x; done;; "clean") echo "cleaning thumbnails cache" rm -rf ${SRC}/*/.thumb echo "cleaned";; esac fi