Find Largest Image Dimensions in Folder

images

I need a command which will allow me to search a folder of images for the images with the biggest width and the biggest height. As of now I'm using XNViewMP to find this info, but I'd like a faster way using a command or a Thunar Custom Action.

UPDATE: There are some good solutions for this using Thunar's Custom Actions: https://forum.xfce.org/viewtopic.php?id=9106

The last one on the second page that uses YAD is the best I've found.

Best Answer

To use identify from ImageMagic with sorting, let's change the output format to make that easier:

We want to sort on width or height, so they should be easy to address as sort key field. To output width and height as the first two columns, and then the filename, we use "%w %h %f\n".

The resulting list of lines of the form w h somefile.png are then sorted numerically (-n) on either the first column, the width, or second column, the height.
We sort reverse (-r) so the larges value appears first:

Sorting by width in the first column:

identify -format "%w %h %f\n" *.png | sort -n -r -k 1

Sorting by height, which is in the second column:

identify -format "%w %h %f\n" *.png | sort -n -r -k 2

The part of the line after the second space is only the file name, so we do not need to escape it; Just cutting off the two columns gives a clean filename, (as long as the names do not contain newlines).

If you are not interested in the whole list, but only a few of the larges files, use head on the result:

identify -format "%w %h %f\n" *.png | sort -n -r -k 2 | head -n 3

When we show only the largest file, or files, maybe we do not really care about the size anymore, but need the clean filenames:

identify -format "%w %h %f\n" *.png | sort -n -r -k 2 | head -n 3 | cut -d ' ' -f 3-  
Related Question