FocalLengthIn35mmFormat calculation

Started by PhotoAddict, January 26, 2015, 02:30:56 PM

Previous topic - Next topic

VlCTOR

I'm sorry, Phil - that brilliant code blinded me. :D

Phil Harvey

OK, how about this?:

ValueConv => q{
return $val[2] * $val[1] if $val[2];
my $scl = {
'DSC-V1' => 4.84,
'DSLR-A500' => 1.5,
'DSLR-A550' => 1.5,
'Canon EOS REBEL T2i' => 1.6,
'Canon EOS 650D' => 1.6,
'iPhone 4S' => 7.6,
'DSC-S700' => 6.0,
'COOLPIX S200' => 6.0,
}->{$val[0]};
return $scl ? int($scl * $val[1]) : undef;
},
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

VlCTOR

That's great! I will learn to programming on Perl based on your code samples. If someone tells me about my code, which isn't good, I'm going to ask him to shut up because I was trained to coding by famous Phil Harvey.  ;)
The second version is more difficult to understand, so I had to make some effort to understand how it works. However, I found a slight omission - in the second line should also be a function int()
In fact, the int function was redundant for FocalLengthIn35mmFormat calculations.
At first, there were errors of non-compliance with data types -"Not an integer...". For this reason I added the int() function.
But now everything works without the use of rounding. So far, I can not understand how it works, because we multiply two numbers with a floating point for the tag 'int16u'. I believe that Exiftool performs the necessary conversions.

Phil Harvey

Quote from: VlCTOR on November 29, 2019, 09:13:13 PM
in the second line should also be a function int()

Right.

QuoteBut now everything works without the use of rounding. So far, I can not understand how it works, because we multiply two numbers with a floating point for the tag 'int16u'. I believe that Exiftool performs the necessary conversions.

Yes.  ExifTool rounds to the nearest integer when writing an integer tag with a floating-point value.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).