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
  • 193,181
  • 53
  • 473
  • 722
Usermaxn
  • 197
  • 6
  • 1
    Divide the sizes to get the aspect ratio? landscape: 16/9 = 1.77... and in portrait: 9/16=0.5625. – Marco Jun 23 '23 at 05:16
  • how do I divide the sizes in command line and how do I pass the result of the check to grep? maybe I should make it a function and have it have a if statement – Usermaxn Jun 25 '23 at 01:27

1 Answers1

2

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,100
  • 6
  • 14