Calculate the real aspect ratio of an image

Started by sinus, December 27, 2020, 03:51:53 PM

Previous topic - Next topic

sinus

Hi all
Does someone know a possibility to calculate the aspect ratio (like 3:2 or 16:9) of an image with help of the variables with the math-functions?
Means variables like

{File.LongEdge|cast:int;math:div,{File.ShortEdge|cast:int}}

But this one works not.
Maybe it is simply not possible.

But maybe someone has an idea?
Best wishes from Switzerland! :-)
Markus

herman

Wouldn't {File.AspectRatio} be easier to use?
Enjoy!

Herman.

sinus

Thanks, Herman, for your intput.

Unfortunately this variable ({File.AspectRatio}) works only for uncropped images.
As soon I have altered them with Photoshop, it shows a completely wrong number (e.g. 4:3, thougth is is 16:9) or it shows simply a 0 (null).

At least on my images, I do not know, when and with what value this variable is feeded, but here it works only for new images.

That is why I am searching a better way.
Best wishes from Switzerland! :-)
Markus

Mario

The aspect ratio is calculated from the physical width and height of the file, as returned by the image library.
The same values you see in IMatch and returned by {File.Width} and {File.Height}. Are these variables correct for your image?
When I crop a 16:9 image to 5:4 in Ps, IMatch afterwards also displays 4:5 for the {File.AspectRatio}
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on December 27, 2020, 08:02:33 PM
The aspect ratio is calculated from the physical width and height of the file, as returned by the image library.
The same values you see in IMatch and returned by {File.Width} and {File.Height}. Are these variables correct for your image?
When I crop a 16:9 image to 5:4 in Ps, IMatch afterwards also displays 4:5 for the {File.AspectRatio}

Thanks, Mario

The variables {File.Width} and {File.Height} are correct, but not the {File.AspectRatio}, as you can see in my attachement.
After cropping in PS Aspect Ratio shows 0.

I checked this also in VarToy, it is the same.
The Variable what I used:

{File.Width|pereplace:.==} x {File.Height|pereplace:.==}
{File.Width|numcomp:gt,{File.Height},Q,H}
{File.AspectRatio}


That is the reason, why I want to calculate the real AspectRatio.
Best wishes from Switzerland! :-)
Markus

Mario

#5
The pixel dimensions you have used match none of the standard a:b ratios. Hence the variable returns 0.
Your variable should be {File.LongEdge|cast:int;math:div,{File.ShortEdge|cast:int},2}. The cast is implicit with math and if you don't specify the digits parameter, 0 decimal digits is assumed.

Since, for example, 2548 / 800 gives 3.21, the variable returns 3 if digits=0 and 3.21 if digits=2
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Mario, brilliant!

Thanks for your input. This was a great help. Now I get good and correct results!  :)

Now I get e.g. 3.67 as a result and I have lerned somewhere on the net to count further with "Verhältnisse berechnen"  8) I think, finally I will get a good result.

I have to know this, because specialy one client does layouts, where he ask for aspect ratios like 3:4, but also 16:9 and 12:7).
Best wishes from Switzerland! :-)
Markus

Mario

I have enhanced the {File.AspectRatio} variable a bit for the next release.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on December 28, 2020, 11:33:30 AM
I have enhanced the {File.AspectRatio} variable a bit for the next release.

Thanks, Mario, cool!
Best wishes from Switzerland! :-)
Markus