Composite tags to compute the aspect ratio and format of an image

Started by CWCorrea, February 20, 2024, 08:19:07 PM

Previous topic - Next topic

CWCorrea

Recently I found myself needing to classify images by aspect ratio, so I defined the Composite tag "AspectRatio" using the values of the ImageWidth and ImageHeight tags. I also defined the "ImageFormat" tag to identify whether the image is in square, portrait or landscape format.

I share the aspect_ratio.config file as an example for newbies like me of how to call a perl function in a user-defined tag.

exiftool -config aspect_ratio.config -aspectratio# -aspectratio -imageformat image.jpg

Aspect Ratio                     : 1.3333
Aspect Ratio                     : 4:3
Image Format                     : Landscape

I hope this is useful to someone in the forum.

Christian W.

StarGeek

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

CWCorrea

Quote from: StarGeek on February 21, 2024, 01:22:17 AMPreviously on Exiftool

I should have used the search function before doing this.

My config file is similar to yours with the difference that I used a recursive function to compute the GCD. :D

I couldn't resist adding more functionality to the ImageFormat tag and added a list of standard aspect ratios, so now the ImageFormat tag returns Std. Landscape or Std. Portrait when the image has a standard aspect ratio like 4:3 or 16:9.

It would be interesting if Phil added tags like AspectRatio and ImageFormat as composite tags to exiftool as these tags would be useful. Maybe I should open a Feature Request.  ;)

StarGeek

Quote from: CWCorrea on February 21, 2024, 02:50:35 PMI used a recursive function to compute the GCD. :D

Yeah, I saw that.  In mine I simply copy/pasted some code I found somewhere, probably on one of the StackExchange sites.

QuoteI couldn't resist adding more functionality to the ImageFormat tag and added a list of standard aspect ratios, so now the ImageFormat tag returns Std. Landscape or Std. Portrait when the image has a standard aspect ratio like 4:3 or 16:9.

That's why I'm replacing my config with yours in my notes.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).