photools.com Community

IMatch Discussion Boards => General Discussion and Questions => Topic started by: Damit on March 12, 2025, 07:51:48 PM

Title: How to get VarToy to display file height in inches-Math variable not working.
Post by: Damit on March 12, 2025, 07:51:48 PM
Hello,

I am trying to get a variable expression that will give me the file height in inches. I will then apply this to file width so I can display the actual image size in inches

I know that I can get that value by dividing the File Height by the Resolution ({File.MD.Exif::Main\282\XResolution\0}. However, after reading the proper sections in the guide I cannot get the math function to work.

I tried {File.Height;Math:Div,{File.MD.Exif::Main\283\YResolution\0}} but it did not work, and I cannot figure out why.  Any help would be greatly appreciated!
Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: Mario on March 12, 2025, 08:21:43 PM
Take care for spelling and case (div not Div), according to the help, cast when needed, output the variables you use in VarToy to see wht they contain. etc.
Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: PandDLong on March 12, 2025, 09:05:58 PM
Quote from: Damit on March 12, 2025, 07:51:48 PMHello,

I am trying to get a variable expression that will give me the file height in inches. I will then apply this to file width so I can display the actual image size in inches

I know that I can get that value by dividing the File Height by the Resolution ({File.MD.Exif::Main\282\XResolution\0}. However, after reading the proper sections in the guide I cannot get the math function to work.

I tried {File.Height;Math:Div,{File.MD.Exif::Main\283\YResolution\0}} but it did not work, and I cannot figure out why.  Any help would be greatly appreciated!


I recently did something similar for scanned photos and I use the following expression to get widthxheight in inches.

{File.Width|cast:int;math:div,{File.MD.JFIF::Main\3\XResolution\0|default:{File.MD.Exif::Main\282\XResolution\0}},1}x{File.Height|cast:int;math:div,{File.MD.JFIF::Main\5\YResolution\0|default:{File.MD.Exif::Main\283\YResolution\0}},1}

Two notes about the above:

1. I decided to round off at one decimal point

2. Some files have the resolution in JFIF::Main and others have it in EXIF::Main (and some have it in both) - I think it is mostly driven by file format and the source of the file (eg. scan, photo editor, etc).  However, sometimes when it is in both, JFIF is the resolution I want to check and EXIF has 72 (which I think is related to a display resolution), so I use JFIF if it is populated.

So far, this has worked for me  - your results may vary.

I hope that is helpful.

Michael





Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: Damit on March 12, 2025, 09:25:40 PM
Thank you Micheal!!! 8)
I really appreciate this greatly! I was following the clues left by Mario and I had figured out the need for the cast, which I was aware of, but did not think I needed to include it because both the values were already numbers.
After Mario's clue, I realized the comma might be the problem, but I keep getting a rounded number and it was rounded the wrong way. The quotient of the two numbers (5633 and 1500) us 3.755 but I kept getting 3 in vartoy.  I then looked at your example and realized that ",1" at the end was for one decimal point.  Strangely the result was 3.8. If I put in a ",2" I got 3.76, and ",3" not surprisingly, 7.55.  I am not sure why not including a comma and a value at the end would cause the value to return as 3.

Even with your example, if I remove the ",1" it will revert to rounding down.  Stil trying to figure that out, because I may want to the variable to round the number to the nearest integer for conciseness.
Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: PandDLong on March 12, 2025, 11:46:52 PM
Interesting observation on the rounding down.  I think I tried ,0  to get just an integer value but I decided pretty quick I wanted one decimal point so never tested to see if ,0 rounds properly or just truncates (ie. rounds down).

Btw - I think the cast is needed to get rid of the thousands separator   (eg. 3,200 pixels becomes 3200 when cast:int)

Michael
Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: Damit on March 13, 2025, 07:49:44 PM
Anyone have any idea why it rounds down with a ,0 or nothing at the end?
Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: Mario on March 13, 2025, 08:18:45 PM
Tip: You can display the file dimensions in inches using the "Dimensions" attribute in File Window layouts.

H: {File.Height|cast:real}
W: {File.Width|cast:real}
XRes: {File.MD.Exif::Main\282\XResolution|cast:int}
YRes: {File.MD.Exif::Main\283\YResolution|cast:int}
H: {File.Height|cast:real;math:div,{File.MD.Exif::Main\283\YResolution|cast:int},2}
W: {File.Width|cast:real;math:div,{File.MD.Exif::Main\283\YResolution|cast:int},2}

gives

H: 1.806,00
W: 2.554,00
XRes: 96
YRes: 96
H: 18,81
W: 26,60

which is correct? Where is the problem?
Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: Damit on March 13, 2025, 09:08:30 PM
Thank you. The problem is described in post #3.

The problem is that if you have a value like 3.755 as the result of dividing the file height with the file Y resolution and you have a ",0" or nothing in the area I have bolded below, then the result would be 3 instead of 4.  So, for some reason, the variable expression is strictly rounding down, instead of to the nearest number. However, if you put a ",1" or a ",2" it will round to the nearest number with said digits.

{File.Height|cast:int;math:div,{File.MD.JFIF::Main\5\YResolution\0|default:{File.MD.Exif::Main\283\YResolution\0}},1}

So I am trying to figure out why it is rounding down, because, preferably, I want to list the value as an integer but rounded to the correct integer.
Title: Re: How to get VarToy to display file height in inches-Math variable not working.
Post by: Mario on March 13, 2025, 10:16:54 PM
The ,1 is the number of digital places to output and this is also considered for rounding. < 0.5 is rounded down, else up.

{File.AT.Notes.Num}
{File.AT.Notes.Num|cast:real;math:div,72,4}
{File.AT.Notes.Num|cast:real;math:div,72,3}
{File.AT.Notes.Num|cast:real;math:div,72,2}
{File.AT.Notes.Num|cast:real;math:div,72,1}

gives

3.755,00
52,1528
52,153
52,15
52,2

Not sure what else you expect. There is no ceil or floor operator in IMatch variables.