If statement syntax error with config file.

Started by ColtenH, July 17, 2024, 12:03:30 PM

Previous topic - Next topic

ColtenH

I am trying to take the tag GPS Img Direction from a 0-360 value to a +/-180 value and output it as the tag KMLHeading. Here is the code I have in the config file.
line 279 KMLHeading => {
line 280 Require => {
line 281 0 => 'GPSImgDirection',
line 282 },
line 283 my $kmlh = $val[0],
line 284 if ($val[0] > 180) {
line 285 ValueConv => '$kmlh = ($val[0]-180)*-1';
line 286 }
line 287 ValueConv => $kmlh
line 288 },
The error I am getting when running through the command prompt is
syntax error at custom.config line 284, near "if"

I am unsure what is wrong and if there is a more proper way to code this.

Phil Harvey

There are a few problems, and your math skills are dubious. ;)

Try this:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        KMLHeading => {
            Require => 'GPSImgDirection',
            ValueConv => '$val - ($val > 180 ? 360 : 0)',
        },
    },
);

1;

- 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 ($).

ColtenH

Thank you.
Could you explain this portion so i can learn. '$val - ($val > 180 ? 360 : 0)'
As for the math what is incorrect about it? Example 270-180=90, then inverting 90 * (-1) for -90

Phil Harvey

Quote from: ColtenH on July 17, 2024, 01:19:43 PMCould you explain this portion so i can learn. '$val - ($val > 180 ? 360 : 0)'
As for the math what is incorrect about it? Example 270-180=90, then inverting 90 * (-1) for -90

Your example choice of -90 degrees is unfortunate.

What if the direction is 359 degrees?:  359 - 180 = 179.  Negating this is -179.  But the relative direction should be -1, right? (1 degree to the left).

My code subtracts 360 if the value is greater than 180.  So 359 turns into -1.

- 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 ($).