make pa_exifautotran be more specific - only "skip" the known SOS error, and dont touch file if the output of the rotate is 0 bytes -- JUST IN CASE

This commit is contained in:
2022-08-03 17:54:00 +10:00
parent 7ad75830e2
commit 70521501ab

View File

@@ -18,7 +18,7 @@ EOF
exit 0;;
esac
case $(exiftool -t -s -s -s -n -IFD0:Orientation -IFD1:Orientation "$i") in
case $(jpegexiforient "$i") in
1) transform="";;
2) transform="-flip horizontal";;
3) transform="-rotate 180";;
@@ -32,9 +32,20 @@ EOF
if test -n "$transform"; then
echo Executing: jpegtran -copy all $transform "$i" >&2
jpegtran -copy all $transform "$i" > tempfile
rm "$i"
jpegtran -copy all $transform "$i" > tempfile 2> err
ret=$?
err=`cat err`
if [ "$ret" = "2" ] && [ "$err" != "Invalid SOS parameters for sequential JPEG" ]; then
echo "$0: FAILED to rotate jpeg with unknown failure - dont change file"
rm err
rm tempfile
exit 1
fi
# last sanity check - make sure tempfile is not empty
if [ -s tempfile ]; then
rm err
mv tempfile "$i"
jpegexiforient -1 "$i"
jpegexiforient -1 "$i" > /dev/null
fi
fi
done