Skip to content

Instantly share code, notes, and snippets.

@obihann
Created August 18, 2014 13:49
Show Gist options
  • Save obihann/4d4675250dd2cc4b3c4d to your computer and use it in GitHub Desktop.
Save obihann/4d4675250dd2cc4b3c4d to your computer and use it in GitHub Desktop.
Organize Images by Size
#!/bin/sh
for f in *.jpeg
do
BASE=$(basename "$f" .jpg)
mv "$f" "$BASE.jpg"
done
for f in *.jpg
do
HEIGHT=$(sips -g pixelHeight "$f" | tail -n1 | cut -d' ' -f4)
WIDTH=$(sips -g pixelWidth "$f" | tail -n1 | cut -d' ' -f4)
BASE=$(basename "$f" .jpg)
mv "$f" "$BASE"."$WIDTH"x"$HEIGHT".jpg
done
for f in *.png
do
HEIGHT=$(sips -g pixelHeight "$f" | tail -n1 | cut -d' ' -f4)
WIDTH=$(sips -g pixelWidth "$f" | tail -n1 | cut -d' ' -f4)
BASE=$(basename "$f" .png)
mv "$f" "$BASE"."$WIDTH"x"$HEIGHT".png
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment