[multimedia] Add apply-exif-orientation.sh

This commit is contained in:
Matteo Cypriani 2016-01-22 15:19:18 +01:00
parent 336f9160f7
commit d6acb4cd3f
3 changed files with 61 additions and 0 deletions

1
bin/apply-exif-orientation Symbolic link
View File

@ -0,0 +1 @@
../multimedia/apply-exif-orientation.sh

15
multimedia/README Executable file → Normal file
View File

@ -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

View File

@ -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 <image_file>" >&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"