I have many photos. How to search files by its dimensions? For example, i want to search images with exact dimensions 500 x 500 pixels. Is there any utility for this task?
2 Answers
With exiftool:
exiftool -q -r -if '$ImageHeight == 500 &&
$ImageWidth == 500' -p '$Directory/$FileName' /some/dir
You can use the identify command that's part of ImageMagick to do this:
$ identify rose.jpg
rose.jpg JPEG 640x480 sRGB 87kb 0.050u 0:01
The 640x480 is the dimensions of the image, rose.jpg.
Using the find command you could do something like this:
$ find somedir -iname '*.jpg' -exec identify {} \;
So for your example:
$ find somedir -iname '*.jpg' -exec "identify {} awk '{print $1, $3}' \
| grep '500x500'" \;
References
-
4This is suitable only for files without whitespace characters in their name. Better use
-formatoption:identify -format '%P %f\n' *.{jpg,png,gif} | grep '^500x500 '.manatwork– manatwork2013-05-04 14:16:19 +00:00Commented May 4, 2013 at 14:16 -
@manatwork, that technique didn't work too well for me, running it in a directory where there aren't any png, jpg, or gif files yields this error: "identify: unable to open image `*.jpg': @ error/blob.c/OpenBlob/2517."2013-05-04 16:25:55 +00:00Commented May 4, 2013 at 16:25
-
Being a comment, I kept it simple. Feel free to combine it with your original
findbased code.manatwork– manatwork2013-05-04 16:37:02 +00:00Commented May 4, 2013 at 16:37 -
I like your thinking on the approach, just was putting a comment to it in case others encountered it too 8-).2013-05-04 16:41:35 +00:00Commented May 4, 2013 at 16:41