mirror of https://github.com/Phantop/dotfiles
padjpeg: jxl support
This commit is contained in:
parent
fcf20f2a1b
commit
c51f8bf262
31
bin/padjpeg
31
bin/padjpeg
|
@ -2,6 +2,15 @@
|
||||||
set -e # exit on failure
|
set -e # exit on failure
|
||||||
IFS=$(printf '\n\t') # smarter ifs
|
IFS=$(printf '\n\t') # smarter ifs
|
||||||
|
|
||||||
|
jxl=0
|
||||||
|
if file "$1" | grep 'JPEG XL'; then
|
||||||
|
jxl="$1"
|
||||||
|
out=$(mktemp --suffix=.jpg)
|
||||||
|
djxl "$1" "$out"
|
||||||
|
shift
|
||||||
|
set -- "$out" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
test "$RATIOW" || RATIOW=16
|
test "$RATIOW" || RATIOW=16
|
||||||
test "$RATIOH" || RATIOH=9
|
test "$RATIOH" || RATIOH=9
|
||||||
imageh=$(identify -format %h "$1")
|
imageh=$(identify -format %h "$1")
|
||||||
|
@ -11,8 +20,9 @@ img_ratio=$(printf '3 k %u %u / p' "$imagew" "$imageh" | dc)
|
||||||
|
|
||||||
wide="$(echo "$img_ratio > $des_ratio" | bc )"
|
wide="$(echo "$img_ratio > $des_ratio" | bc )"
|
||||||
if [ "$wide" -gt 0 ] ; then
|
if [ "$wide" -gt 0 ] ; then
|
||||||
mv "$1" ".$1_padjpegtmp.jpg"
|
backup=$(mktemp)
|
||||||
jpegtran -rotate 90 -outfile "$1" ".$1_padjpegtmp.jpg"
|
mv "$1" "$backup"
|
||||||
|
jpegtran -rotate 90 -outfile "$1" "$backup"
|
||||||
imageh=$(identify -format %h "$1")
|
imageh=$(identify -format %h "$1")
|
||||||
imagew=$(identify -format %w "$1")
|
imagew=$(identify -format %w "$1")
|
||||||
des_ratio=$(printf '3 k %u %u / p' "$RATIOH" "$RATIOW" | dc)
|
des_ratio=$(printf '3 k %u %u / p' "$RATIOH" "$RATIOW" | dc)
|
||||||
|
@ -20,14 +30,17 @@ fi
|
||||||
|
|
||||||
des_width=$(printf '1 k %f %u * p' "$des_ratio" "$imageh" | dc | cut -d. -f1)
|
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)
|
offset=$(printf '%u %u - 2 / p' "$des_width" "$imagew" | dc)
|
||||||
|
outfile="$(dirname "$1")/tran_$(basename "$1")"
|
||||||
|
|
||||||
if test "$REFLECT"; then
|
test "$REFLECT" && mode=r || mode=f
|
||||||
jpegtran -crop "$des_width"r+"$offset" -outfile "tran_$1" "$1"
|
jpegtran -crop "$des_width$mode+$offset" -outfile "$outfile" "$1"
|
||||||
else
|
|
||||||
jpegtran -crop "$des_width"f+"$offset" -outfile "tran_$1" "$1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$wide" -gt 0 ] ; then
|
if [ "$wide" -gt 0 ] ; then
|
||||||
mv ".$1_padjpegtmp.jpg" "$1"
|
mv "$backup" "$1"
|
||||||
jpegtran -rotate 270 -outfile "tran_$1" "tran_$1"
|
jpegtran -rotate 270 -outfile "$outfile" "$outfile"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$jxl" != 0 ]; then
|
||||||
|
cjxl -e 8 "$outfile" "tran_$jxl"
|
||||||
|
rm "$outfile" "$1"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue