Mercurial > geeqie.yaz
diff 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 |
line wrap: on
line diff
--- a/plugins/rotate/geeqie-rotate Sat Jun 13 22:19:57 2009 +0000 +++ b/plugins/rotate/geeqie-rotate Mon Jun 15 19:13:45 2009 +0000 @@ -1,15 +1,59 @@ -#!/bin/sh +#!/bin/bash -x + +# This is a helper script that rotate image files according to the metadata +# requirements: ImageMagick, exiftran, exiv2 + +GQ_METADATA_DIR="$HOME/.local/share/geeqie/metadata" -# This is a helper script that rotate jpeg files using jpegtran +rotate() +{ + ext=`echo "${1##*.}" |tr "[:upper:]" "[:lower:]"` + [ "x$ext" == "x" ] && return 1 #no extension + + gq_metadata="$GQ_METADATA_DIR/$1.gq.xmp" + if [ -f "$gq_metadata" ]; then + gq_orientation=`exiv2 -PXkv "$gq_metadata"|grep Xmp.tiff.Orientation|sed -e "s|Xmp.tiff.Orientation *||"` + else + gq_orientation= + fi -rotation=$1 -shift + case "$ext" in + jpg|jpeg) + [ -n "$gq_orientation" ] && exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1" + if exiftran -aip "$1" ; then + # exiftran ignores xmp, set it manually + exiv2 -M "set Xmp.tiff.Orientation 1" "$1" + #http://dev.exiv2.org/issues/show/639 + [ -n "$gq_orientation" ] && exiv2 -M "set Xmp.tiff.Orientation 1" \ + -M "set Exif.Image.Orientation 1" "$gq_metadata" + return 0 + fi + ;; + + tif|tiff|png) + [ -n "$gq_orientation" ] && exiv2 -M "set Exif.Image.Orientation $gq_orientation" "$1" + if mogrify -auto-orient "$1" ; then + # mogrify ignores xmp, set it manually + exiv2 -M "set Xmp.tiff.Orientation 1" "$1" + #http://dev.exiv2.org/issues/show/639 + [ -n "$gq_orientation" ] && exiv2 -M "set Xmp.tiff.Orientation 1" \ + -M "set Exif.Image.Orientation 1" "$gq_metadata" + return 0 + fi + ;; + *) #not supported + return 0 + ;; + esac +} +# iterate over files on commandline for file in "$@" ; do - tmp="$file".$$ - if jpegtran -rotate "$rotation" -copy all -outfile "$tmp" "$file"; then - mv -f "$tmp" "$file"; - else - rm -f "$tmp"; - fi + # we got only one file for each group, typically the main one + # get the sidecars: + geeqie -r --get-sidecars:"$file" |while read sidecar ; do + # the main file is included in the sidecar file list, no special handling is required + rotate "$sidecar" + done done +