2023-06-03 16:00:25 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
set -e # exit on failure
|
|
|
|
IFS=$(printf '\n\t') # smarter ifs
|
|
|
|
|
|
|
|
test "$RATIOW" || RATIOW=16
|
|
|
|
test "$RATIOH" || RATIOH=9
|
|
|
|
imageh=$(identify -format %h "$1")
|
|
|
|
imagew=$(identify -format %w "$1")
|
|
|
|
des_ratio=$(printf '3 k %u %u / p' "$RATIOW" "$RATIOH" | dc)
|
|
|
|
img_ratio=$(printf '3 k %u %u / p' "$imagew" "$imageh" | dc)
|
|
|
|
|
|
|
|
wide="$(echo "$img_ratio > $des_ratio" | bc )"
|
|
|
|
if [ "$wide" -gt 0 ] ; then
|
|
|
|
mv "$1" ".$1_padjpegtmp.jpg"
|
|
|
|
jpegtran -rotate 90 -outfile "$1" ".$1_padjpegtmp.jpg"
|
|
|
|
imageh=$(identify -format %h "$1")
|
|
|
|
imagew=$(identify -format %w "$1")
|
|
|
|
des_ratio=$(printf '3 k %u %u / p' "$RATIOH" "$RATIOW" | dc)
|
|
|
|
fi
|
|
|
|
|
|
|
|
des_width=$(printf '1 k %f %u * p' "$des_ratio" "$imageh" | dc | cut -d. -f1)
|
|
|
|
offset=$(printf '%u %u - 2 / p' "$des_width" "$imagew" | dc)
|
2023-08-14 12:49:00 +00:00
|
|
|
|
|
|
|
if test "$REFLECT"; then
|
|
|
|
jpegtran -crop "$des_width"r+"$offset" -outfile "tran_$1" "$1"
|
|
|
|
else
|
|
|
|
jpegtran -crop "$des_width"f+"$offset" -outfile "tran_$1" "$1"
|
|
|
|
fi
|
2023-06-03 16:00:25 +00:00
|
|
|
|
|
|
|
if [ "$wide" -gt 0 ] ; then
|
|
|
|
mv ".$1_padjpegtmp.jpg" "$1"
|
|
|
|
jpegtran -rotate 270 -outfile "tran_$1" "tran_$1"
|
|
|
|
fi
|