#!/bin/sh set -e USMPARAMS="-a 400% -r 0.3" sizecmd() { djpeg $1 | pnmfile | sed 's/.*, //; s/ *maxval.*//; s/ by / /' } sizepnm() { pnmfile $1 | sed 's/.*, //; s/ *maxval.*//; s/ by / /' } create_scaled() { # Try to find the smallest scaled version of the image that contains # the desired size in=$1 xi=$2 yi=$3 xt=$4 yt=$5 out=$6 x1=$xt y1=`echo "$yi*$xt/$xi+1" | bc` y2=$yt x2=`echo "$xi*$yt/$yi+1" | bc` if [ `expr $x1 "*" $y1` -gt `expr $x2 "*" $y2` ] then x=$x1 y=$y1 else x=$x2 y=$y2 fi echo Using $x x $y for $xt x $yt djpeg $in | srgbtoxyz -s NTSC | xyzscale -xysize $x $y | xyzusm $USMPARAM | xyztosrgb -c > $out.1 set -- `sizepnm $out.1` a=$1 b=$2 if [ $a -lt $xt -o $b -lt $yt ] then x=`expr $x + 1` y=`expr $y + 1` echo "Too small (got $a x $b), retrying with $x x $y" djpeg $in | srgbtoxyz -s NTSC | xyzscale -xysize $x $y | xyzusm $USMPARAM | xyztosrgb > $out.1 set -- `sizepnm $out.1` a=$1 b=$2 if [ $a -lt $xt -o $b -lt $yt ] then echo "Still too small (got $a x $b), aborting" exit fi fi dxh=0 dyh=0 if [ $a -gt $xt ] then dxh=`echo '(' $a - $xt ')' / 2 | bc` echo X is too big, offset $dxh fi if [ $b -gt $yt ] then dyh=`echo '(' $b - $yt ')' / 2 | bc` echo Y is too big, offset $dyh fi pnmcut $dxh $dyh $xt $yt $out.1 | pnmdepth 255 | cjpeg -quality 90 -sample 1x1,1x1,1x1 > $out rm -f $out.1 } for i do echo $i: set -- `sizecmd $i` a=$1 b=$2 echo $a x $b if [ $a -gt $b ] then echo landscape t_size='192 128' s_size='384 256' m_size='768 512' l_size='1536 1024' xl_size='3072 2048' h_size='6144 4096' else echo portrait t_size='128 192' # Base/16 s_size='256 384' # Base/4 m_size='512 768' # Base l_size='1024 1536' # 4 Base xl_size='2048 3072' # 16 Base h_size='4096 6144' # 64 Base fi (create_scaled $i $a $b $t_size s/t.$i) (create_scaled $i $a $b $s_size s/s.$i) (create_scaled $i $a $b $m_size s/m.$i) (create_scaled $i $a $b $l_size s/l.$i) #(create_scaled $i $a $b $xl_size s/xl.$i) #(create_scaled $i $a $b $h_size s/h.$i) #djpeg s/t.$i | ppmquant 256 | ppmtogif > s/t.`basename $i .jpg`.gif (cd s && rm -f o.$i && ln -s ../$i o.$i) done