Eu fiz um script alguns anos atrás para esse propósito. Eu chamo de autorot , mas você pode usar qualquer nome para isso. Você deve modificar as variáveis
dimkonica=2112x2816
dimcanon=3264x2448
para valores que correspondem aos tamanhos de suas fotos. Aqui está o script:
#!/bin/bash
if [ "$1" == "" ]
then
echo "Usage: $0 <jpeg-file> [lossy]"
echo "Auto-rotate *lossless* with jhead,"
echo "or optionally, if bad image dimensions,"
echo "auto-orient *lossy* with convert"
exit
fi
name="$1"
name=${name%.*}
#echo $1
#echo $name
if [ "$1" == "$name".jpg ] || [ "$1" == "$name".JPG ] || [ "$1" == "$name".jpeg ] || [ "$1" == "$name".JPEG ]
then
echo hej>/dev/null
else
echo "Bad! $1 not a jpeg-file"
exit
fi
dimkonica=2112x2816
dimcanon=3264x2448
dim=$(identify -ping "$1"|sed -e s/.*JPEG\ // -e s/\ .*//)
gw0=$(echo "$dim"|sed s/x.*//)
gw1=$((gw0/16*16))
gh0=$(echo "$dim"|sed s/.*x//)
gh1=$((gh0/16*16))
if [ "$dim" == "$dimkonica" ] || [ "$dim" == "$dimcanon" ]
then
echo "jhead: Original dimension for jhead: $1: $dim"
jhead -autorot "$1"
else
if [ "$gw0" == "$gw1" ] && [ "$gh0" == "$gh1" ]
then
echo "jhead: Good dimension for jhead: $1: $gw0"x"$gh0"
jhead -autorot "$1"
else
if [ "$2" == "lossy" ]
then
echo "convert: Bad dimension for jhead: $1: $dim"
while [ "$ans" != "yes" ] && [ "$ans" != "n" ] && [ "$ans" != "no" ]
do
echo -n "make a lossy rotation the image? (yes/no) "
read ans
if [ "$ans" == "yes" ]
then
echo Converted: original saved, rotated copy named "$name"_r.jpg
convert -auto-orient "$1" "$name"_r.jpg
fi
done
else
echo "Bad dimension for jhead: $1: $dim"
fi
fi
fi