Main Menu

Config file issues

Started by oc, September 05, 2023, 10:38:20 PM

Previous topic - Next topic

oc

I'm struggling figuring out how to create a config file so I can write two lines of custom XMP metadata as follow:

<internal:firstTag>some|data|here</internal:firstTag>
<internal:secondTag>someDateStamp</internal:secondTag>

-----

Here is what I have so far, which keeps giving me errors:

%Image::ExifTool::UserDefined:Shortcuts = (
MyShortcut => ['XMP-internal:firstTag','XMP-internal:secondTag'],
);

%Image::ExifTool::UserDefined:: internal = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-internal', 2 => 'Image' },
    NAMESPACE => { 'internal' => 'http://ns.exiftool.com/XMP/XMP-internal/1.0/' },
    WRITABLE => 'string',
   
    firstTag => { Writable => 'string' },
    secondTag => { Writable => 'string' },
);
1;

I keep getting either syntax errors or Warning: Tag 'firstTag' is not defined.

Any help would be very much appreciated.

StarGeek

There are two parts to creating a new XMP namespace.  The first section is to add the new namespace to the main XMP table.  It is covered by this part in the Example Config file
%Image::ExifTool::UserDefined = (
    # new XMP namespaces (eg. xxx) must be added to the Main XMP table:
    'Image::ExifTool::XMP::Main' => {
        # namespace definition for examples 8 to 11
        xxx => { # <-- must be the same as the NAMESPACE prefix
            SubDirectory => {
                TagTable => 'Image::ExifTool::UserDefined::xxx',
                # (see the definition of this table below)
            },
        },
        # add more user-defined XMP namespaces here...
    },
);

And you also have to make a definition of the new namespace.  That is covered further down in the config
# This is a basic example of the definition for a new XMP namespace.
# This table is referenced through a SubDirectory tag definition
# in the %Image::ExifTool::UserDefined definition above.
# The namespace prefix for these tags is 'xxx', which corresponds to
# an ExifTool family 1 group name of 'XMP-xxx'.
%Image::ExifTool::UserDefined::xxx = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-xxx', 2 => 'Image' },
    NAMESPACE => { 'xxx' => 'http://ns.myname.com/xxx/1.0/' },
    WRITABLE => 'string', # (default to string-type tags)
    # Example 8.  XMP-xxx:NewXMPxxxTag1 (an alternate-language tag)
    # - replace "NewXMPxxxTag1" with your own tag name (eg. "MyTag")
    NewXMPxxxTag1 => { Writable => 'lang-alt' },
    # Example 9.  XMP-xxx:NewXMPxxxTag2 (a string tag in the Author category)
    NewXMPxxxTag2 => { Groups => { 2 => 'Author' } },
    # Example 10.  XMP-xxx:NewXMPxxxTag3 (an unordered List-type tag)
    NewXMPxxxTag3 => { List => 'Bag' },
);

The first section is easy, just copy/paste it and change xxx to the name of your new namespace

%Image::ExifTool::UserDefined = (
    # new XMP namespaces (eg. xxx) must be added to the Main XMP table:
    'Image::ExifTool::XMP::Main' => {
        # namespace definition for examples 8 to 11
        internal => { # <-- must be the same as the NAMESPACE prefix
            SubDirectory => {
                TagTable => 'Image::ExifTool::UserDefined::internal',
                # (see the definition of this table below)
            },
        },
        # add more user-defined XMP namespaces here...
    },
);

Your second part looks good except for the space in %Image::ExifTool::UserDefined:: internal.  And because you set WRITABLE to default as 'string', you don't need to duplicate it in the tag name part

The shortcut section is unrelated to the actual new definitions.  It appears first in the example config file, but I tend to place it at the end.  Just my personal preference as I am more likely to edit that section than the main parts and it's easier to jump to the end of the file.

Combined, you get
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::XMP::Main' => {
        internal => { # <-- must be the same as the NAMESPACE prefix
            SubDirectory => {
                TagTable => 'Image::ExifTool::UserDefined::internal',
                # (see the definition of this table below)
            },
        },
    },
);

%Image::ExifTool::UserDefined::internal = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-internal', 2 => 'Image' },
    NAMESPACE => { 'internal' => 'http://ns.exiftool.com/XMP/XMP-internal/1.0/' },
    WRITABLE => 'string',
    firstTag => { },
    secondTag => { },
);

%Image::ExifTool::UserDefined::Shortcuts = (
MyShortcut => ['XMP-internal:firstTag','XMP-internal:secondTag'],
);
1;

Sample output, note that the config file is needed to write, but because this is XMP, it isn't needed to read.  New tags in EXIF or IPTC IIM will not display the tag name without the config file.
C:\>exiftool -config test.config -P -overwrite_original -firstTag="some|data|here" -secondTag="someDateStamp" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -xmp:all y:\!temp\Test4.jpg
[XMP-x]         XMPToolkit                      : Image::ExifTool 12.64
[XMP-internal]  FirstTag                        : some|data|here
[XMP-internal]  SecondTag                       : someDateStamp
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

oc

This is so fantastic! Thank you so much StarGeek.

I've used the exact configuration you've posted and now the data does write.

One small glitch I have -- which appears only when viewing the metadata in Photoshop -- is a _1_ that appears between the namespace and the tag.

Any thoughts as to where this is coming from, why ExifTool doesn't show it, and/or how I can fix it?

Screenshot 2023-09-06 at 11.01.28 AM.png 

Thanks again!

StarGeek

I can't comment on what Photoshop is doing, because I have no idea, but if you look at the raw XMP that is actually in the file, those characters do not exist

Example (trailing padding snipped)
C:\exiftool -G1 -a -s -xmp -b y:\!temp\Test4.jpg
<?xpacket begin='�' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 12.64'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

 <rdf:Description rdf:about=''
  xmlns:internal='http://ns.exiftool.com/XMP/XMP-internal/1.0/'>
  <internal:firstTag>some|data|here</internal:firstTag>
  <internal:secondTag>someDateStamp</internal:secondTag>
 </rdf:Description>
</rdf:RDF>
</x:xmpmeta>                                                                                 
<?xpacket end='w'?>
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

oc

Yes, @GlobalModerator, you're right, nothing in the config file or in the raw XMP contained those characters. That's why I was so confused.

After much trial and error, I discovered that, somehow, Photoshop seem to retain some traces of metadata in memory and, if it finds the same metadata again, in the same image, it keeps incrementing that number. A very weird bug, but only if my Namespace differed slightly from the one already in the original image prior to me writing the metatada.

Interestingly, this issue would immediately disappear when you quit and relaunch Photoshop. But, after viewing the metadata of the first image, it would reappear.

I was able to solve the issue by simply exactly matching the Namespace to the original. Again, only so Photoshop would display the right results. The embedded metadata was actually correct.

Thanks a lot for the help.