Friday, April 3, 2015

Sorting a Bunch of Images by Resolution

I'd collected a heap of desktop wallpaper images over the years, and wanted to sort them by resolution.

This is the best way I found to do it, using the identify command from the ImageMagick tools. Of course I had to tweak it a little bit for my own purposes, namely to capture .jpeg files as well a .jpg, and to copy the files rather than move.

Script I ended up using:

#!/bin/bash for image in ./*.{jpg,jpeg} ; do res=$(identify -format %wx%h\\n $image); mkdir -p $res; cp -p $image $res; done