diff --git a/bin/apply-exif-orientation b/bin/apply-exif-orientation new file mode 120000 index 0000000..ce48ed4 --- /dev/null +++ b/bin/apply-exif-orientation @@ -0,0 +1 @@ +../multimedia/apply-exif-orientation.sh \ No newline at end of file diff --git a/multimedia/README b/multimedia/README old mode 100755 new mode 100644 index 61ffec3..2765b0d --- a/multimedia/README +++ b/multimedia/README @@ -1,3 +1,18 @@ +# apply-exif-orientation.sh # + +apply-exif-orientation.sh retrieves the Orientation EXIF tag from an +image file and rotates the actual image data according to the said +orientation. The EXIF Orientation tag is deleted in the process. The +goal is to allow the image to be displayed correctly by tools that don't +handle EXIF metadata (such as ImageMagick's display). + +EXIF information is manipulated using exiftool, shipped with the +Image::ExifTool Perl module (Debian package: libimage-exiftool-perl). +Image is rotated using ImageMagick's convert. + +Warning: no backup of the original file is made! + + # just-play-something.sh # As its name indicates, the main goal of just-play-something.sh is to put diff --git a/multimedia/apply-exif-orientation.sh b/multimedia/apply-exif-orientation.sh new file mode 100755 index 0000000..2b2e46f --- /dev/null +++ b/multimedia/apply-exif-orientation.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# +# apply-exif-orientation.sh, Copyright © 2016 Matteo Cypriani +# +# This program is free software. It comes without any warranty, to +# the extent permitted by applicable law. You can redistribute it +# and/or modify it under the terms of the Do What The Fuck You Want +# To Public License, Version 2, as published by Sam Hocevar. See +# http://sam.zoy.org/wtfpl/COPYING for more details. +# +# This script gets the Orientation EXIF tag from an image file (with +# exiftool) and rotates the image (with convert) to apply the +# orientation to the image data; the EXIF Orientation tag is deleted. +# +# About EXIF orientations, see: +# http://jpegclub.org/exif_orientation.html + +if [ $# -ne 1 ] ; then + echo "Usage: $0 " >&2 + exit 1 +fi + +SOURCE="$1" + +ORIENTATION=$(exiftool -n -veryShort -Orientation "$SOURCE" | sed -n 's/^.*: //p') + +if [ "$ORIENTATION" = "" ] ; then + echo "No EXIF Orientation tag. Nothing to do." + exit 0 +fi + +case $ORIENTATION in + 1) echo "Horizontal orientation. Nothing to do." ; exit 0 ;; + 3) ORIENTATION=180 ;; + 6) ORIENTATION=90 ;; + 8) ORIENTATION=-90 ;; + *) echo "Orientation code $ORIENTATION unknown" >&2 ; exit 2 ;; +esac + +echo "Rotating image by $ORIENTATION°" +TMP=$(mktemp) +convert -rotate $ORIENTATION "$SOURCE" "$TMP" +exiftool -quiet -overwrite_original_in_place -Orientation= "$TMP" +chmod a+r "$TMP" +mv "$TMP" "$SOURCE"