read value from src-file, calculate new value, write to dst-file

Started by snahl, March 13, 2013, 08:53:59 PM

Previous topic - Next topic

snahl

Hi Phil,

here is a tricky one for me - probably not for you.

What I want to do is to read the value of -XMP-crs:CropRight in src-file.tif and write it - after a calculation - to dst-file.xmp.
The calculation is {1 - $val(XMP-crs:CropRight)}. The result shall be written to XMP:crs:CropRight in the dst-file.xmp.

Eventually I have to do this for crs:CropTop, :CropBottom, :CropLeft and :CropRight.

To copy the needed XMP-crs:tags one-to-one from one file to another I am using the following command:
exiftool.exe -P -tagsfromfile converted\src-file.tif -@ CropTif2xmp.args dst-file.xmp

My trial-error attempt doing a calculation in the file CropTif2xmp.args unsurprisingly failed.
-XMP-crs:CropRight < XMP-crs:{1-$CropRight}

The solutions seems to be something like you describe in the config documentation (https://exiftool.org/config.html) and to obtain the desired calculation I assume that I need to properly prepare an .ExifTool_config file.

So the questions are (assuming I am on the right track):

How do I have to modify .ExifTool_config to use exisiting xmp-tags?
How can I do calculations as described above?

For the calculation I figured something like this might work - nested in the .ExifTool_config:

{
CropRightCalc => {
   Require => 'XMP-crs:CropRight',
   ValueConv => '1 - $val',},
}

Then the file CropTif2Xmp.args would write the modified value from src-file.tif to dst-file.xmp

-XMP-crs:CropRight < CropRightCalc

So far I only inserted the required namespace, but after that I am lost.
Hope you can get me a step further on this.
Thanks, Hans.


%Image::ExifTool::UserDefined::crs = (
    GROUPS        => { 0 => 'XMP', 1 => 'XMP-crs', 2 => 'Image' },
    NAMESPACE     => { 'crs' => 'http://ns.adobe.com/camera-raw-settings/1.0/' },
    WRITABLE      => 'string',
    # replace "NewXMPxxxTag1" with your own tag name (ie. "MyTag")
#    NewXMPxxxTag1 => { Writable => 'lang-alt' },
#    NewXMPxxxTag2 => { Groups => { 2 => 'Author' } },
#    NewXMPxxxTag3 => { List => 'Bag' },
    # example structured XMP tag
    NewXMPxxxStruct => {
        # the "Struct" entry defines the structure fields
        Struct => {
            # optional namespace prefix and URI for structure fields
            # (required only if different than NAMESPACE above)
            NAMESPACE => { 'test' => 'http://x.y.z/test/' },
            # optional structure name (used for warning messages only)
            STRUCT_NAME => 'MyStruct',
            # optional rdf:type property for the structure
            TYPE => 'http://x.y.z/test/xystruct',
            # structure field definitions (very similar to tag definitions)
            X => { Writable => 'integer' },
            Y => { Writable => 'integer' },
            # a nested structure...
            Things => {
                List => 'Bag',
                Struct => {
                    NAMESPACE => { thing => 'http://x.y.z/thing/' },
                    What  => { },
                    Where => { },
                },
            },
        },
        List => 'Seq', # structures may also be elements of a list
    },
    # Each field in the structure has an automatically-generated
    # corresponding flattened tag with an ID that is the concatenation
    # of the original structure tag ID and the field name (after
    # capitalizing the first letter of the field name if necessary).
    # The Name and/or Description of these flattened tags may be changed
    # if desired, but all other tag properties are taken from the
    # structure field definition.  When this is done, the "Flat" flag
    # must also be set in the tag definition.  For example:
    NewXMPxxxStructX => { Name => 'SomeOtherName', Flat => 1 },
);
Dig-IT-all

snahl

I figured it out thanks to this post in the forum:

Possible to do a multiplication when copying tags?
https://exiftool.org/forum/index.php/topic,3302.msg14863.html

All is good. See you around.
Dig-IT-all