Skip to content

Instantly share code, notes, and snippets.

@alexarje
Created November 25, 2018 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexarje/3783cb50b9c699eb6cce7c952b732463 to your computer and use it in GitHub Desktop.
Save alexarje/3783cb50b9c699eb6cce7c952b732463 to your computer and use it in GitHub Desktop.
Sort images based on direction (portrait/landscape)
# Based on: https://unix.stackexchange.com/questions/294341/shell-script-to-separate-and-move-landscape-and-portrait-images
# make directories
mkdir portraits
mkdir landscapes
# Check that all images have correct rotation
jhead -autorot *.jpg
jhead -autorot *.JPG
# move files
for f in ./*.JPG
do
r=$(identify -format '%[fx:(h>w)]' "$f")
if [[ r -eq 1 ]]
then
mv "$f" portraits
else
mv "$f" landscapes
fi
done
for f in ./*.jpg
do
r=$(identify -format '%[fx:(h>w)]' "$f")
if [[ r -eq 1 ]]
then
mv "$f" portraits
else
mv "$f" landscapes
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment