Skip to content

Instantly share code, notes, and snippets.

@chanux
Created August 14, 2012 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chanux/3351562 to your computer and use it in GitHub Desktop.
Save chanux/3351562 to your computer and use it in GitHub Desktop.
Classify landscape and portrait images in a directory.
#!usr/bin/env bash
# This script accepts a directory name and classifies
# portrait and landscape images in that directory.
if [ $# == 0 ];then
echo "$0 <path to image directory>"
exit 1
else
DIR=$1
fi
PORTDIR=$DIR/portrait
LANDDIR=$DIR/landscape
mkdir -p $PORTDIR $LANDDIR
for file in $(ls $DIR)
do
if [[ $file == *.png || $file == *.jpg || $file == *.PNG || $file == *.JPG ]]; then
width=$(identify -format %w "$DIR/$file")
height=$(identify -format %h "$DIR/$file")
if [[ $width -lt $height ]]; then
mv $DIR/$file $PORTDIR
else
mv $DIR/$file $LANDDIR
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment