ExifTool Forum

ExifTool => Newbies => Topic started by: Tr on February 25, 2014, 05:28:14 PM

Title: Best way to create a tag alias for reading *and* writing
Post by: Tr on February 25, 2014, 05:28:14 PM
Tried this approach:

%Image::ExifTool::UserDefined::Shortcuts = (
    IPTC_Credit => 'IPTC:Credit',
    XMP_Credit => 'XMP:Credit',
);

Got message:
exiftool -IPTC_Credit="This is the IPTC_Credit" hs-2013-35-a-full_tif.tif
Warning: Tag 'IPTC_Credit' does not exist
Nothing to do.

thanks.
Title: Re: Best way to create a tag alias for reading *and* writing
Post by: Phil Harvey on February 25, 2014, 07:26:07 PM
Quite right.  ExifTool can not currently write a shortcut tag where the group is specified for the target tag.  This is an oversight.  I will see about adding this ability in the next release (ExifTool 9.54).

- Phil
Title: Re: Best way to create a tag alias for reading *and* writing
Post by: Tr on February 26, 2014, 10:18:47 AM
Thanks Phil.

In the meantime, is there anyway to extract *both* IPTC:Credit and XMP:Credit into a csv file and keep them separated without the -G0 option?  As of now, they are both extracted into the same column header: 'Credit'.

We don't want to deal with the group names for ~60 tags we are dealing with.  Hence, no -G option.  But in this particular case we do want to keep the 2 Credit(s) separate to validate and modify each independently.

Would a Composite Tag help in this case?  Is there an example of how to write to a Composite Tag?

Thanks so much.
Title: Re: Best way to create a tag alias for reading *and* writing
Post by: Phil Harvey on February 26, 2014, 10:50:30 AM
Ah.  I was wondering why you were doing this.

Your shortcut idea wouldn't have worked anyway, because actual tag names would still be used for the column headings.

From the documentation for the -csv option:

If the -a option is used to allow duplicate tag names, the duplicate tags are only included in the CSV output if the column headings are unique.

So the only way to do what you want without adding a group name is to rename the tag by overriding the definition (not recommended) or create Composite tag to duplicate the tag with a different name (as you mentioned).  The sample config file (https://exiftool.org/config.html) has a number of examples.

- Phil

Title: Re: Best way to create a tag alias for reading *and* writing
Post by: Tr on February 26, 2014, 01:03:27 PM

Below is my Composite Attempt.  I am getting the following message:
exiftool -IPTC_Credit="This is IPTC_Credit." hs-2013-35-a-full_tif.tif
    0 image files updated
    1 image files unchanged

'Image::ExifTool::Composite' => {
      IPTC_Credit => {
            Require => { 0 => 'IPTC:Credit' },
            Writable => 'string',
            PrintConv => '$val',
            PrintConvInv => '$val'
        }, 
        XMP_Credit => {
            Require => { 0 => 'XMP:Credit' },
            Writable => 'string',
            PrintConv => '$val',
            PrintConvInv => '$val'
        }, 
}

Thanks for any assistance.
Title: Re: Best way to create a tag alias for reading *and* writing
Post by: Phil Harvey on February 26, 2014, 01:15:04 PM
Right.  You want to write these tags too.  Creating a user-defined writable Composite tag is a bit tricky.  Sorry, I should have realized this and provided an example:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        IPTC_Credit => {
            Require => { 0 => 'IPTC:Credit' },
            Writable => 1,
            WriteAlso => {
                'IPTC:Credit' => '$val',
            },
            ValueConv => '$val',
        }, 
        XMP_Credit => {
            Require => { 0 => 'XMP:Credit' },
            Writable => 1,
            WriteAlso => {
                'XMP:Credit' => '$val',
            },
            ValueConv => '$val',
        }, 
    },
);


The "WriteAlso" definition allows you to write any associated tags that you want (not only limited to the Require'd tags).  "Writable" may be any true value since the write format is not checked by the Composite tag.  I also changed your PrintConv's to ValueConv's, which is how it should be done (otherwise you'll see a nasty "HASH" value if you use the -n option).

- Phil

Edit: I realized the ValueConvInv's weren't necessary, so I removed them from the example.  The necessary inverse conversions are handled by the WriteAlso tags.
Title: Re: Best way to create a tag alias for reading *and* writing
Post by: Tr on February 26, 2014, 01:29:47 PM
Awesome!  Thanks Phil.  This was a nasty issue for us reading/writing the 2 Credit(s) in/out of .csv and now it's resolved.   :D :D :D :D