Mercurial > geeqie.yaz
comparison plugins/rotate/geeqie-rotate @ 1641:34c71cbbbd26
improved rotation script
- applies the orientation from metadata
- uses exiftran for jpeg an ImageMagick for other files
author | nadvornik |
---|---|
date | Mon, 15 Jun 2009 19:13:45 +0000 |
parents | f6c8b76d41ca |
children | 61bd3a2f633d |
comparison
equal
deleted
inserted
replaced
1640:ab5945017b4a | 1641:34c71cbbbd26 |
---|---|
1 #!/bin/sh | 1 #!/bin/bash -x |
2 | 2 |
3 # This is a helper script that rotate jpeg files using jpegtran | 3 # This is a helper script that rotate image files according to the metadata |
4 # requirements: ImageMagick, exiftran, exiv2 | |
4 | 5 |
5 rotation=$1 | 6 GQ_METADATA_DIR="$HOME/.local/share/geeqie/metadata" |
6 shift | |
7 | 7 |
8 rotate() | |
9 { | |
10 ext=`echo "${1##*.}" |tr "[:upper:]" "[:lower:]"` | |
11 [ "x$ext" == "x" ] && return 1 #no extension | |
12 | |
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 *||"` | |
16 else | |
17 gq_orientation= | |
18 fi | |
19 | |
20 case "$ext" in | |
21 jpg|jpeg) | |
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" | |
29 return 0 | |
30 fi | |
31 ;; | |
32 | |
33 tif|tiff|png) | |
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" | |
41 return 0 | |
42 fi | |
43 ;; | |
44 *) #not supported | |
45 return 0 | |
46 ;; | |
47 esac | |
48 } | |
49 | |
50 # iterate over files on commandline | |
8 for file in "$@" ; do | 51 for file in "$@" ; do |
9 tmp="$file".$$ | 52 # we got only one file for each group, typically the main one |
10 if jpegtran -rotate "$rotation" -copy all -outfile "$tmp" "$file"; then | 53 # get the sidecars: |
11 mv -f "$tmp" "$file"; | 54 geeqie -r --get-sidecars:"$file" |while read sidecar ; do |
12 else | 55 # the main file is included in the sidecar file list, no special handling is required |
13 rm -f "$tmp"; | 56 rotate "$sidecar" |
14 fi | 57 done |
15 done | 58 done |
59 |