Home » Questions » Computers [ Ask a new question ]

How to sort images into folders, based on resolution?

How to sort images into folders, based on resolution?

Background: I've got a folder full of saved desktop pictures. I'd like to put them into folders, based on their resolution - 1024x768, etc. Creating the folders on the fly is a bonus. Currently, the images are all in a folder, but some of them are in sub-folders. I can merge them by hand, if that makes things easier.

Asked by: Guest | Views: 263
Total answers/comments: 3
Guest [Entry]

"Seriously, thanks for replying, everyone! I've come back to this, more experienced, and most of the comments here make more sense now.

I tweaked @zatatlan's script slightly to accommodate spaces in filenames and to add more file extensions.

#!/bin/bash

shopt -s nullglob # The script spits errors if this is not set and there are, say, no *.png files.
for image in *.jpg *.JPG *.jpeg *.JPEG *.gif *.GIF *.bmp *.BMP *.png *.PNG;
do res=$(identify -format %wx%h\\n ""$image"");
mkdir -p $res;
mv ""$image"" $res;
done"
Guest [Entry]

"It is possible to use imagemagick to detect image resolution. Wrap it in a bash loop and there you go. I won't wait until I get home to a bash shell, so here is something off top of my head. The syntax is probably wrong, but it might give you some clues.

for image in $(`*.jpg`) do
res=`identify $image | grep -o 'Resolution:'`
if [ ! -d $res ]; then
mkdir $res
fi

mv $image $res
done

The script creates directories on the fly. Both bash and imagemagick are available for mac."
Guest [Entry]

A basic way that will give a rough order of resolution is to organize by file size. This is something that should be built into any OS, so you don't need anything special. The BIG catch with this is that the format for your photos would need to be the same for this to work. This isn't a perfect solution, but it may be an easy stop-gap until you find something that actually fits the bill.