13 June 2006

I once used this script to resize and rotate a bunch of images. It reads the EXIF tag for orientation, then rotates the image appropriately and resizes it to either 1024x768 or 768x1024. All of this uses ImageMagick. Consider this public domain.


#!/bin/sh
TARGET_PATH=$1
if [ ! -d "$TARGET_PATH" ] ; then
echo "$0: Not a directory: $1"
exit 2
fi
shift
while [ -n "$1" ] ; do
if [ ! -r "$1" ] ; then
echo "$0: Cannot read file: $1"
exit 1
fi
ORIENTATION=$(identify -format '%[EXIF:Orientation]' $1)
case "$ORIENTATION" in
"1") # Rechtop
convert $1 -resize 1024x768 $TARGET_PATH/$1
;;
"3") # Ondersteboven
convert $1 -rotate 180 -resize 1024x768 $TARGET_PATH/$1
;;
"6") # Kwart slag tegen klok in gedraaid
convert $1 -rotate 90 -resize 768x1024 $TARGET_PATH/$1
;;
"8") # Kwart slag met klok mee gedraaid
convert $1 -rotate -90 -resize 768x1024 $TARGET_PATH/$1
;;
"*")
echo "Whoa! Unknown orientation: $ORIENTATION. (Was it reflected?)"
esac
shift
done

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home