#!/bin/ksh # Given input TIFFs under a base directory, generates the following # derivative images: # - thumbnail GIF (150px in long axis) (suffix t.gif) # - 'R' JPG (640px in long axis) (suffix r.jpg) # - 'V' JPG (unscaled) (suffix v.jpg) INPUT_BASE_PATH=/master/mss/mnwp/ OUTPUT_BASE_PATH=/service/mss/mssmisc/mnwp ALCHEMY=/usr/local/bin/alchemy R_SIZE=600 T_SIZE=150 JPG_PARAMETERS="-j -q" GIF_PARAMETERS="-d0 -c64 -g" # a function to cook an individual file in the three ways described above process_file() { subdir=$1 inputfile=$2 # determine the orientation of the image, and choose # the appropriate Alchemy scaling comand to match orientation=`${ALCHEMY} -x1 ${inputfile} 2>/dev/null | \ awk '/Width:/ {w=$2} /Height:/ {h=$2} END { if (h>w){ print "-Y" } else { print "-X" } }'` filenamebase=`basename $inputfile .tif` #filenamebase=${filenamebase%"u"} # rename the TIFF to XXXXXXu.tif #mv ${filenamebase}.tif ${filenamebase}u.tif # thumbnail GIF outputfile="${filenamebase}t.gif" echo "Converting file ${inputfile} to ${outputfile}" ${ALCHEMY} "${orientation}d${T_SIZE} -+ ${GIF_PARAMETERS} \ ${inputfile} ${outputfile} ${OUTPUT_BASE_PATH}/${subdir}/" # R JPG outputfile="${filenamebase}r.jpg" echo "Converting file ${inputfile} to ${outputfile}" ${ALCHEMY} "${orientation}d${R_SIZE} -+ ${JPG_PARAMETERS} \ ${inputfile} ${outputfile} ${OUTPUT_BASE_PATH}/${subdir}/" # V JPG outputfile="${filenamebase}v.jpg" echo "Converting file ${inputfile} to ${outputfile}" ${ALCHEMY} "${orientation} -+ ${JPG_PARAMETERS} \ ${inputfile} ${outputfile} ${OUTPUT_BASE_PATH}/${subdir}/" } cd ${INPUT_BASE_PATH} for dir in $(find . -type d) do mkdir -p ${OUTPUT_BASE_PATH}/${dir} echo "Working on directory ${dir}:" for f in `ls $dir/*.tif 2>/dev/null` do process_file $dir $f done done