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 *||"`
22 [ -n "$gq_orientation" ] && exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
23 if exiftran -aip "$1" ; then
24 # exiftran ignores xmp, set it manually
25 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
26 #http://dev.exiv2.org/issues/show/639
27 [ -n "$gq_orientation" ] && exiv2 -M "set Xmp.tiff.Orientation 1" \
28 -M "set Exif.Image.Orientation 1" "$gq_metadata"
34 [ -n "$gq_orientation" ] && exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
35 if mogrify -auto-orient "$1" ; then
36 # mogrify ignores xmp, set it manually
37 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
38 #http://dev.exiv2.org/issues/show/639
39 [ -n "$gq_orientation" ] && exiv2 -M "set Xmp.tiff.Orientation 1" \
40 -M "set Exif.Image.Orientation 1" "$gq_metadata"
52 ext=`echo "${3##*.}" |tr "[:upper:]" "[:lower:]"`
53 [ "x$ext" = "x" ] && return 4 #no extension
73 if [ "x$1" = "x-g" ] ; then
80 if [ "x$1" = "x-r" ] ; then
88 if [ "x$1" = "x-t" ] ; then
93 if [ -n "$rotation" ] ; then
94 if [ "x$rotation" = "x0" ] ; then
97 if [ "x$rotation" = "x2" ] ; then
101 if [ "x$rotation" = "x3" ] ; then
102 mogrify_param="-rotate 180"
105 if [ "x$rotation" = "x4" ] ; then
106 mogrify_param="-flip"
109 if [ "x$rotation" = "x5" ] ; then
110 mogrify_param="-transpose"
113 if [ "x$rotation" = "x6" ] ; then
114 mogrify_param="-rotate 90"
117 if [ "x$rotation" = "x7" ] ; then
118 mogrify_param="-transverse"
121 if [ "x$rotation" = "x8" ] ; then
122 mogrify_param="-rotate -90"
127 # iterate over files on commandline
128 for file in "$@" ; do
129 if [ -n "$get_sidecars" ] ; then
130 # we got only one file for each group, typically the main one
132 geeqie -r --get-sidecars:"$file" |while read sidecar ; do
133 # the main file is included in the sidecar file list, no special handling is required
137 if [ -n "$rotate_image_file" ] ; then
138 if [ -n "$preserve_mtime" ] ; then
139 mtime=`mktemp /tmp/geeqie-rotate.XXXXXXXXXX` || exit 3
140 touch --reference="$file" "$mtime"
143 rotate_image_file "$exiftran_param" "$mogrify_param" "$file"
146 if [ -n "$preserve_mtime" ] ; then
147 touch --reference="$mtime" "$file"
150 if [ $ret -eq 4 ] ; then