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-