Created
August 14, 2012 18:38
-
-
Save chanux/3351562 to your computer and use it in GitHub Desktop.
Classify landscape and portrait images in a directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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