Exiftool Config help

Started by blue-j, May 27, 2022, 06:58:18 PM

Previous topic - Next topic

blue-j

The config shared with the app has this composite tag definition:

# calculate physical image size based on resolution
        PhysicalImageSize => {
            Require => {
                0 => 'ImageWidth',
                1 => 'ImageHeight',
                2 => 'XResolution',
                3 => 'YResolution',
                4 => 'ResolutionUnit',
            },
            ValueConv => '$val[0]/$val[2] . " " . $val[1]/$val[3]',
            # (the @prt array contains print-formatted values)
            PrintConv => 'sprintf("%.1f x %.1f $prt[4] @ $prt[2] ppi", split(" ",$val))',
        },


I'm not sure it's honoring the resolution unit.  Attached is an image with a resolution unit of cm, as an example.  It reports 56 ppi when it should report 56 ppcm.  How to fix?

- J

StarGeek

Just change ppi to ppcm in the sprintf function?
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

blue-j

Well, actually this is not the latest version Phil has shared:

        # calculate physical image size based on resolution
        PhysicalImageSize => {
            Require => {
                0 => 'ImageWidth',
                1 => 'ImageHeight',
                2 => 'XResolution',
                3 => 'YResolution',
                4 => 'ResolutionUnit',
            },
            ValueConv => '$val[0]/$val[2] . " " . $val[1]/$val[3]',
            # (the @prt array contains print-formatted values)
            PrintConv => 'sprintf("%.1fx%.1f $prt[4]", split(" ",$val))',
        },


this outputs a string like

4.3x5.6 cm

it no longer reports the resolution it seems?

You can't just replace the ppi with ppcm as it needs to be dynamically based on resolution unit.

- J

Hayo Baan

As you can see, the output unit is based on that of the ResolutionUnit tag. So if that is cm, the output would be cm.

Say image is 3000 by 6000 pixels and the resolution is 300ppi (i.e. XResolution and YResolution are 300 and ResolutionUnit is inches), then the resulting physical image size is 3000/300=10 by 6000/300=20 inches. This is exactly what would be reported by the config as shared.

Note: the problem with the first config you shared is that it assumed the resolution unit was always inches (hence ppi). If you really like to have the ppi/ppcm reported as well, then you could alter the config as follows:
        # calculate physical image size based on resolution
        PhysicalImageSize => {
            Require => {
                0 => 'ImageWidth',
                1 => 'ImageHeight',
                2 => 'XResolution',
                3 => 'YResolution',
                4 => 'ResolutionUnit',
            },
            ValueConv => '$val[0]/$val[2] . " " . $val[1]/$val[3]',
            # (the @prt array contains print-formatted values)
            PrintConv => 'sprintf("%.1fx%.1f $prt[4] @ $prt[2] %s", $val[0], $val[1], $prt[4] eq "cm" ? "ppcm" : "ppi")',
        },
Hayo Baan – Photography
Web: www.hayobaan.nl

StarGeek

Quote from: blue-j on May 29, 2022, 01:19:12 AMYou can't just replace the ppi with ppcm as it needs to be dynamically based on resolution unit.

My mistake for not reading carefully enought :D
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

blue-j

You are both very kind and generous with your knowledge.  Thanks for your attention to this!  Phil, I think this change, if you approve, should be included in the example config...?

- J

blue-j

Quote        # calculate physical image size based on resolution
        PhysicalImageSize => {
            Require => {
                0 => 'ImageWidth',
                1 => 'ImageHeight',
                2 => 'XResolution',
                3 => 'YResolution',
                4 => 'ResolutionUnit',
            },
            ValueConv => '$val[0]/$val[2] . " " . $val[1]/$val[3]',
            # (the @prt array contains print-formatted values)
            PrintConv => 'sprintf("%.1fx%.1f $prt[4] @ $prt[2] %s", $val[0], $val[1], $prt[4] eq "cm" ? "ppcm" : "ppi")',
        },


This outputs:

242.0 x 316.0 cm @ 56 ppcm

But i believe we need to divide the width and height by the resolution to convey rendered, "physical" size?

The output for the sample file should be:

4.3cm x 5.6 cm @ 56 ppcm

instead?

- J


Hayo Baan

Oops, my bad. Change the code to:
        # calculate physical image size based on resolution
        PhysicalImageSize => {
            Require => {
                0 => 'ImageWidth',
                1 => 'ImageHeight',
                2 => 'XResolution',
                3 => 'YResolution',
                4 => 'ResolutionUnit',
            },
            ValueConv => '$val[0]/$val[2] . " " . $val[1]/$val[3]',
            # (the @prt array contains print-formatted values)
            PrintConv => 'sprintf("%.1fx%.1f $prt[4] @ $prt[2] %s", $val[0]/$val[2], $val[1]/$val[3], $prt[4] eq "cm" ? "ppcm" : "ppi")',
        },

Hayo Baan – Photography
Web: www.hayobaan.nl

blue-j

You're very kind to help!!  Yes indeed that code produced precisely the output I was looking for, and I think it will be valued by many others.

: )

- J

Phil Harvey

I don't think this should be included in the release version for 3 reasons.

1. The XResolution tag already provides the information you've added to this Composite tag.

2. This information is misleading if the X and YResolution are different.

3. The stated resolution units are incorrect if the ResolutionUnit is neither "cm" nor "inches" (ie. "None").

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

blue-j

Thank you, Phil for sharing your insight on this.

Quote from: Phil Harvey on May 30, 2022, 05:25:29 AM
1. The XResolution tag already provides the information you've added to this Composite tag.

In the sample file, X and YResolution are in the JFIF namespace and are just a single value of density (eg 56).  EXIF/TIFF seems the same.  Can you explain more what you mean?

Quote from: Phil Harvey on May 30, 2022, 05:25:29 AM
2. This information is misleading if the X and YResolution are different.

Awesome point.  I've never personally seen a file with varying resolutions but I'm sure you have.

Quote from: Phil Harvey on May 30, 2022, 05:25:29 AM
3. The stated resolution units are incorrect if the ResolutionUnit is neither "cm" nor "inches" (ie. "None").

Truth.  On my side we just trap for that, but best to keep ExifTool graceful. 

Thank you!
J

Phil Harvey

Quote from: blue-j on May 30, 2022, 03:42:42 PM
Quote from: Phil Harvey on May 30, 2022, 05:25:29 AM
1. The XResolution tag already provides the information you've added to this Composite tag.

In the sample file, X and YResolution are in the JFIF namespace and are just a single value of density (eg 56).  EXIF/TIFF seems the same.  Can you explain more what you mean?

The extra information you have added to the PhysicalImageSize tag is redundant:

Physical Image Size             : 242.0 x 316.0 cm @ 56 ppcm
X Resolution                    : 56
Y Resolution                    : 56
Resolution Unit                 : cm


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

blue-j

Ahhhh!  I see what you mean now!  Well, when people speak of rendered output, they usually in one breath say the physical/output dimensions and the resolution/density.  "cm" and "in" also are not equivalent to "ppi" and "ppcm."  So it's a matter of convenience.  But I see what you mean now, and maybe we will change course.  For one, I do certainly want to trap for varying resolutions/PARs, and no res specified as well, as you mentioned.  Thank you for continually educating me!

- J