How to sort images into folders, based on resolution?

I know it's an over a year topic (sorry about that) but i think someone may need the full working script, so here it is. Taking the ideas here and compiling into a script we get.

#!/bin/bash

for image in *.jpg;
    do res=$(identify -format %wx%h\\n $image);
    mkdir -p $res;
    mv $image $res;
done

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

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.