4 ## @brief This is a helper script that rotates image files according to the metadata
6 ## Requirements: ImageMagick, exiftran, exiv2
9 GQ_METADATA_DIR="$HOME/.local/share/geeqie/metadata"
13 ext=`echo "${1##*.}" |tr "[:upper:]" "[:lower:]"`
14 [ "x$ext" = "x" ] && return 1 #no extension
16 gq_metadata="$GQ_METADATA_DIR/$1.gq.xmp"
17 if [ -f "$gq_metadata" ] ; then
18 gq_orientation=`exiv2 -PXkv "$gq_metadata"|grep Xmp.tiff.Orientation|sed -e "s|Xmp.tiff.Orientation *||"`
26 if [ -n "$gq_orientation" ] ; then
27 exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
30 if exiftran -aip "$1" ; then
31 # exiftran ignores xmp, set it manually
32 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
34 #http://dev.exiv2.org/issues/639
35 if [ -n "$gq_orientation" ] ; then
36 exiv2 -M "set Xmp.tiff.Orientation 1" \
37 -M "set Exif.Image.Orientation 1" "$gq_metadata"
47 if [ -n "$gq_orientation" ] ; then
48 exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
51 if mogrify -auto-orient "$1" ; then
52 # mogrify ignores xmp, set it manually
53 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
55 #http://dev.exiv2.org/issues/639
56 if [ -n "$gq_orientation" ] ; then
57 exiv2 -M "set Xmp.tiff.Orientation 1" \
58 -M "set Exif.Image.Orientation 1" "$gq_metadata"
74 ext=`echo "${3##*.}" |tr "[:upper:]" "[:lower:]"`
75 [ "x$ext" = "x" ] && return 1 #no extension
80 [ $? != 0 ] && return 6
86 [ $? != 0 ] && return 7
97 if [ "x$1" = "x-g" ] ; then
104 if [ "x$1" = "x-r" ] ; then
105 rotate_image_file=yes
112 if [ "x$1" = "x-t" ] ; then
117 if [ -n "$rotation" ] ; then
118 if [ "x$rotation" = "x0" ] ; then
121 if [ "x$rotation" = "x2" ] ; then
122 mogrify_param="-flop"
125 if [ "x$rotation" = "x3" ] ; then
126 mogrify_param="-rotate 180"
129 if [ "x$rotation" = "x4" ] ; then
130 mogrify_param="-flip"
133 if [ "x$rotation" = "x5" ] ; then
134 mogrify_param="-transpose"
137 if [ "x$rotation" = "x6" ] ; then
138 mogrify_param="-rotate 90"
141 if [ "x$rotation" = "x7" ] ; then
142 mogrify_param="-transverse"
145 if [ "x$rotation" = "x8" ] ; then
146 mogrify_param="-rotate -90"
151 # iterate over files on commandline
152 for file in "$@" ; do
153 if [ -n "$get_sidecars" ] ; then
154 # we got only one file for each group, typically the main one
156 geeqie -r --get-sidecars:"$file" |while read sidecar ; do
157 # the main file is included in the sidecar file list, no special handling is required
158 [ ! -w "$sidecar" ] && exit 5
162 # Bourne shell runs DO loops in a sub-shell
164 [ $ret != 0 ] && exit $ret
166 [ ! -w "$file" ] && exit 5
167 if [ -n "$rotate_image_file" ] ; then
168 if [ -n "$preserve_mtime" ] ; then
169 mtime=`mktemp /tmp/geeqie-rotate.XXXXXXXXXX` || exit 3
170 touch --reference="$file" "$mtime"
173 rotate_image_file "$exiftran_param" "$mogrify_param" "$file"
176 if [ -n "$preserve_mtime" ] ; then
177 touch --reference="$mtime" "$file"
180 [ $ret != 0 ] && exit $ret
184 [ $ret != 0 ] && exit $ret