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 [ "$ext" = "" ] && 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 *||")
19 # shellcheck disable=2181
27 if [ -n "$gq_orientation" ] ; then
28 exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
29 # shellcheck disable=2181
32 if exiftran -aip "$1" ; then
33 # exiftran ignores xmp, set it manually
34 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
35 # shellcheck disable=2181
37 #http://dev.exiv2.org/issues/639
38 if [ -n "$gq_orientation" ] ; then
39 exiv2 -M "set Xmp.tiff.Orientation 1" \
40 -M "set Exif.Image.Orientation 1" "$gq_metadata"
41 # shellcheck disable=2181
51 if [ -n "$gq_orientation" ] ; then
52 exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
53 # shellcheck disable=2181
56 if mogrify -auto-orient "$1" ; then
57 # mogrify ignores xmp, set it manually
58 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
59 # shellcheck disable=2181
61 #http://dev.exiv2.org/issues/639
62 if [ -n "$gq_orientation" ] ; then
63 exiv2 -M "set Xmp.tiff.Orientation 1" \
64 -M "set Exif.Image.Orientation 1" "$gq_metadata"
65 # shellcheck disable=2181
81 ext=$(echo "${3##*.}" |tr "[:upper:]" "[:lower:]")
82 [ "$ext" = "" ] && return 1 #no extension
87 # shellcheck disable=2181
88 [ $? != 0 ] && return 6
94 # shellcheck disable=2181
95 [ $? != 0 ] && return 7
106 if [ "$1" = "-g" ] ; then
113 if [ "$1" = "-r" ] ; then
114 rotate_image_file=yes
121 if [ "$1" = "-t" ] ; then
126 if [ -n "$rotation" ] ; then
127 if [ "$rotation" = "0" ] ; then
130 if [ "$rotation" = "2" ] ; then
131 mogrify_param="-flop"
134 if [ "$rotation" = "3" ] ; then
135 mogrify_param="-rotate 180"
138 if [ "$rotation" = "4" ] ; then
139 mogrify_param="-flip"
142 if [ "$rotation" = "5" ] ; then
143 mogrify_param="-transpose"
146 if [ "$rotation" = "6" ] ; then
147 mogrify_param="-rotate 90"
150 if [ "$rotation" = "7" ] ; then
151 mogrify_param="-transverse"
154 if [ "$rotation" = "8" ] ; then
155 mogrify_param="-rotate -90"
160 # iterate over files on commandline
161 for file in "$@" ; do
162 if [ -n "$get_sidecars" ] ; then
163 # we got only one file for each group, typically the main one
165 geeqie -r --get-sidecars:"$file" |while read -r sidecar ; do
166 # the main file is included in the sidecar file list, no special handling is required
167 [ ! -w "$sidecar" ] && exit 5
171 # Bourne shell runs DO loops in a sub-shell
173 [ "$ret" != 0 ] && exit "$ret"
175 [ ! -w "$file" ] && exit 5
176 if [ -n "$rotate_image_file" ] ; then
177 if [ -n "$preserve_mtime" ] ; then
178 mtime=$(mktemp "${TMPDIR:-/tmp}/geeqie-rotate.XXXXXXXXXX") || exit 3
179 touch --reference="$file" "$mtime"
182 rotate_image_file "$exiftran_param" "$mogrify_param" "$file"
185 if [ -n "$preserve_mtime" ] ; then
186 touch --reference="$mtime" "$file"
189 [ "$ret" != 0 ] && exit "$ret"
193 [ "$ret" != 0 ] && exit "$ret"