3 # This is a helper script that rotate image files according to the metadata
4 # requirements: ImageMagick, exiftran, exiv2
6 GQ_METADATA_DIR="$HOME/.local/share/geeqie/metadata"
10 ext=`echo "${1##*.}" |tr "[:upper:]" "[:lower:]"`
11 [ "x$ext" = "x" ] && return 1 #no extension
13 gq_metadata="$GQ_METADATA_DIR/$1.gq.xmp"
14 if [ -f "$gq_metadata" ] ; then
15 gq_orientation=`exiv2 -PXkv "$gq_metadata"|grep Xmp.tiff.Orientation|sed -e "s|Xmp.tiff.Orientation *||"`
23 if [ -n "$gq_orientaqtion" ] ; then
24 exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
27 if exiftran -aip "$1" ; then
28 # exiftran ignores xmp, set it manually
29 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
31 #http://dev.exiv2.org/issues/show/639
32 if [ -n "$gq_orientation" ] ; then
33 exiv2 -M "set Xmp.tiff.Orientation 1" \
34 -M "set Exif.Image.Orientation 1" "$gq_metadata"
44 if [ -n "$gq_orientation" ] ; then
45 exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
48 if mogrify -auto-orient "$1" ; then
49 # mogrify ignores xmp, set it manually
50 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
52 #http://dev.exiv2.org/issues/show/639
53 if [ -n "$gq_orientation" ] ; then
54 exiv2 -M "set Xmp.tiff.Orientation 1" \
55 -M "set Exif.Image.Orientation 1" "$gq_metadata"
71 ext=`echo "${3##*.}" |tr "[:upper:]" "[:lower:]"`
72 [ "x$ext" = "x" ] && return 1 #no extension
77 [ $? != 0 ] && return 6
83 [ $? != 0 ] && return 7
94 if [ "x$1" = "x-g" ] ; then
101 if [ "x$1" = "x-r" ] ; then
102 rotate_image_file=yes
109 if [ "x$1" = "x-t" ] ; then
114 if [ -n "$rotation" ] ; then
115 if [ "x$rotation" = "x0" ] ; then
118 if [ "x$rotation" = "x2" ] ; then
119 mogrify_param="-flop"
122 if [ "x$rotation" = "x3" ] ; then
123 mogrify_param="-rotate 180"
126 if [ "x$rotation" = "x4" ] ; then
127 mogrify_param="-flip"
130 if [ "x$rotation" = "x5" ] ; then
131 mogrify_param="-transpose"
134 if [ "x$rotation" = "x6" ] ; then
135 mogrify_param="-rotate 90"
138 if [ "x$rotation" = "x7" ] ; then
139 mogrify_param="-transverse"
142 if [ "x$rotation" = "x8" ] ; then
143 mogrify_param="-rotate -90"
148 # iterate over files on commandline
149 for file in "$@" ; do
150 if [ -n "$get_sidecars" ] ; then
151 # we got only one file for each group, typically the main one
153 geeqie -r --get-sidecars:"$file" |while read sidecar ; do
154 # the main file is included in the sidecar file list, no special handling is required
155 [ ! -w "$sidecar" ] && exit 5
159 # Bourne shell runs DO loops in a sub-shell
161 [ $ret != 0 ] && exit $ret
163 [ ! -w "$file" ] && exit 5
164 if [ -n "$rotate_image_file" ] ; then
165 if [ -n "$preserve_mtime" ] ; then
166 mtime=`mktemp /tmp/geeqie-rotate.XXXXXXXXXX` || exit 3
167 touch --reference="$file" "$mtime"
170 rotate_image_file "$exiftran_param" "$mogrify_param" "$file"
173 if [ -n "$preserve_mtime" ] ; then
174 touch --reference="$mtime" "$file"
177 [ $ret != 0 ] && exit $ret
181 [ $ret != 0 ] && exit $ret