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 if ! [ -x "$(command -v exiftranx)" ]
15 zenity --title="Geeqie rotate" --info --width=200 --text="Exiftran is not installed" --window-icon=/usr/local/share/pixmaps/geeqie.png 2> /dev/null
24 if ! [ -x "$(command -v exiv2x)" ]
26 zenity --title="Geeqie rotate" --info --width=200 --text="Exiv2 is not installed" --window-icon=/usr/local/share/pixmaps/geeqie.png 2> /dev/null
35 if ! [ -x "$(command -v mogrifyx)" ]
37 zenity --title="Geeqie rotate" --info --width=200 --text="ImageMagick is not installed" --window-icon=/usr/local/share/pixmaps/geeqie.png 2> /dev/null
46 ext=$(echo "${1##*.}" | tr "[:upper:]" "[:lower:]")
47 [ "$ext" = "" ] && return 1 #no extension
49 gq_metadata="$GQ_METADATA_DIR/$1.gq.xmp"
50 if [ -f "$gq_metadata" ]
52 gq_orientation=$(gq_exiv2 -PXkv "$gq_metadata" | grep Xmp.tiff.Orientation | sed -e "s|Xmp.tiff.Orientation *||")
53 # shellcheck disable=2181
61 if [ -n "$gq_orientation" ]
63 gq_exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
64 # shellcheck disable=2181
67 if gq_exiftran -aip "$1"
69 # exiftran ignores xmp, set it manually
70 gq_exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
71 # shellcheck disable=2181
73 #http://dev.exiv2.org/issues/639
74 if [ -n "$gq_orientation" ]
76 gq_exiv2 -M "set Xmp.tiff.Orientation 1" \
77 -M "set Exif.Image.Orientation 1" "$gq_metadata"
78 # shellcheck disable=2181
88 if [ -n "$gq_orientation" ]
90 gq_exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
91 # shellcheck disable=2181
94 if gq_mogrify -auto-orient "$1"
96 # mogrify ignores xmp, set it manually
97 gq_exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
98 # shellcheck disable=2181
100 #http://dev.exiv2.org/issues/639
101 if [ -n "$gq_orientation" ]
103 gq_exiv2 -M "set Xmp.tiff.Orientation 1" \
104 -M "set Exif.Image.Orientation 1" "$gq_metadata"
105 # shellcheck disable=2181
106 [ $? != 0 ] && exit 1
121 ext=$(echo "${3##*.}" | tr "[:upper:]" "[:lower:]")
122 [ "$ext" = "" ] && return 1 #no extension
126 gq_exiftran -i "$1" "$3"
127 # shellcheck disable=2181
128 [ $? != 0 ] && return 6
134 # shellcheck disable=2181
135 [ $? != 0 ] && return 7
156 rotate_image_file=yes
169 if [ -n "$rotation" ]
171 if [ "$rotation" = "0" ]
175 if [ "$rotation" = "2" ]
177 mogrify_param="-flop"
180 if [ "$rotation" = "3" ]
182 mogrify_param="-rotate 180"
185 if [ "$rotation" = "4" ]
187 mogrify_param="-flip"
190 if [ "$rotation" = "5" ]
192 mogrify_param="-transpose"
195 if [ "$rotation" = "6" ]
197 mogrify_param="-rotate 90"
200 if [ "$rotation" = "7" ]
202 mogrify_param="-transverse"
205 if [ "$rotation" = "8" ]
207 mogrify_param="-rotate -90"
212 # iterate over files on commandline
215 if [ -n "$get_sidecars" ]
217 # we got only one file for each group, typically the main one
219 geeqie -r --get-sidecars:"$file" | while read -r sidecar
221 # the main file is included in the sidecar file list, no special handling is required
222 [ ! -w "$sidecar" ] && exit 5
226 # Bourne shell runs DO loops in a sub-shell
228 [ "$ret" != 0 ] && exit "$ret"
230 [ ! -w "$file" ] && exit 5
231 if [ -n "$rotate_image_file" ]
233 if [ -n "$preserve_mtime" ]
235 mtime=$(mktemp "${TMPDIR:-/tmp}/geeqie-rotate.XXXXXXXXXX") || exit 3
236 touch --reference="$file" "$mtime"
239 rotate_image_file "$exiftran_param" "$mogrify_param" "$file"
242 if [ -n "$preserve_mtime" ]
244 touch --reference="$mtime" "$file"
247 [ "$ret" != 0 ] && exit "$ret"
251 [ "$ret" != 0 ] && exit "$ret"