annotate plugins/rotate/geeqie-rotate @ 1723:0e235874877e

write metadata before another opeation - this is implemented for copy and external editor - the unsaved metadata should survive operations like move or rename - saving metadata before delete is pointless
author nadvornik
date Tue, 25 Aug 2009 21:30:50 +0000
parents a15dc91173b4
children f549702f7b41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1707
a15dc91173b4 run the scripts with /bin/sh
nadvornik
parents: 1647
diff changeset
1 #!/bin/sh
1647
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
2
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
3 # This is a helper script that rotate image files according to the metadata
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
4 # requirements: ImageMagick, exiftran, exiv2
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
5
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
6 GQ_METADATA_DIR="$HOME/.local/share/geeqie/metadata"
1616
5b36a6ff55ae Add .desktop files to restore lossless jpeg rotation via editors.
zas_
parents:
diff changeset
7
1647
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
8 rotate()
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
9 {
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
10 ext=`echo "${1##*.}" |tr "[:upper:]" "[:lower:]"`
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
11 [ "x$ext" == "x" ] && return 1 #no extension
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
12
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
13 gq_metadata="$GQ_METADATA_DIR/$1.gq.xmp"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
14 if [ -f "$gq_metadata" ]; then
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
15 gq_orientation=`exiv2 -PXkv "$gq_metadata"|grep Xmp.tiff.Orientation|sed -e "s|Xmp.tiff.Orientation *||"`
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
16 else
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
17 gq_orientation=
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
18 fi
1616
5b36a6ff55ae Add .desktop files to restore lossless jpeg rotation via editors.
zas_
parents:
diff changeset
19
1647
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
20 case "$ext" in
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
21 jpg|jpeg)
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
22 [ -n "$gq_orientation" ] && exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
23 if exiftran -aip "$1" ; then
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
24 # exiftran ignores xmp, set it manually
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
25 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
26 #http://dev.exiv2.org/issues/show/639
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
27 [ -n "$gq_orientation" ] && exiv2 -M "set Xmp.tiff.Orientation 1" \
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
28 -M "set Exif.Image.Orientation 1" "$gq_metadata"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
29 return 0
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
30 fi
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
31 ;;
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
32
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
33 tif|tiff|png)
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
34 [ -n "$gq_orientation" ] && exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
35 if mogrify -auto-orient "$1" ; then
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
36 # mogrify ignores xmp, set it manually
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
37 exiv2 -M "set Xmp.tiff.Orientation 1" "$1"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
38 #http://dev.exiv2.org/issues/show/639
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
39 [ -n "$gq_orientation" ] && exiv2 -M "set Xmp.tiff.Orientation 1" \
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
40 -M "set Exif.Image.Orientation 1" "$gq_metadata"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
41 return 0
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
42 fi
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
43 ;;
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
44 *) #not supported
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
45 return 0
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
46 ;;
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
47 esac
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
48 }
1616
5b36a6ff55ae Add .desktop files to restore lossless jpeg rotation via editors.
zas_
parents:
diff changeset
49
1647
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
50 # iterate over files on commandline
1616
5b36a6ff55ae Add .desktop files to restore lossless jpeg rotation via editors.
zas_
parents:
diff changeset
51 for file in "$@" ; do
1647
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
52 # we got only one file for each group, typically the main one
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
53 # get the sidecars:
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
54 geeqie -r --get-sidecars:"$file" |while read sidecar ; do
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
55 # the main file is included in the sidecar file list, no special handling is required
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
56 rotate "$sidecar"
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
57 done
1616
5b36a6ff55ae Add .desktop files to restore lossless jpeg rotation via editors.
zas_
parents:
diff changeset
58 done
1647
2a779a1855d7 improved rotation script
nadvornik
parents: 1616
diff changeset
59