1

I need a method to find all pictures with a certain aspect ratio, for example 16:9 , such as 1920x1080 1280x720 944x531.

I found this page How to find all images with a certain pixel size using command line? but it only says how to find certain sizes not aspect ratios.

I use bash.

muru
  • 207,228
Usermaxn
  • 247
  • 2
  • 10

1 Answers1

3

You can modify the command from your link
How to find all images with a certain pixel size using command line?

This will print filenames with pictures approximatly landscape 16/9:

find . -iname "*.jpg" -type f -exec identify -format '%w %h %i\n' '{}' \; | awk '$1/$2>1.7 && $1/$2<1.8 {print $3}'

This will do the same with approximatly portrait 9/16:

find . -iname "*.jpg" -type f -exec identify -format '%w %h %i\n' '{}' \; | awk '$1/$2>0.5 && $1/$2<0.6 {print $3}'

Of course you can use the math in awk in more sophisticated way (for better reading only the awk part):

awk 'sqrt((($1/$2)-(16/9))^2)<sqrt(0.5^2) {print $3}'

As awk has no "abs" function, I just use created it using "^2" and "sqrt" to check if the ratio is inside a "delta" (in this example 0.5).

Marco
  • 1,264