How to add custom tags to image metadata?

Started by Velmonte, September 07, 2021, 02:24:33 AM

Previous topic - Next topic

Velmonte

Hello everyone,

I'm tasked with adding specific tags to image metadata that will be accessed by a webserver. I followed the steps outlined in the Exiftool FAQ, step 11 (https://exiftool.org/faq.html), and I'm using the "example.config" file (https://exiftool.org/config.html) as a start, but any attempt at defining my own tag fails. I need to have the following tags in my images as text:

Date
ID
Pole Number
Equipment Type
Issue
Substation
Circuit
Risk Level
Static Image Path
Video Path
Future Prediction
Status


Any help to steer me in the right direction is greatly appreciated! This is my first time working with this kind of data.



greybeard

What have you done so far and what do you mean by "fails"?

Have you followed the instructions in the notes section of the config file?

Do you mean its not picking up the config file or that its just your customization that isn't working?

Velmonte

The config file is picking up, but the tag is either not found or not defined. The command I'm using to test it is...

exiftool -v2 -NewPngTag=Date FILENAME

This after adding the config file to my home directory and renaming it as per the example's instructions.

StarGeek

Quote from: Velmonte on September 07, 2021, 08:44:08 AM
exiftool -v2 -NewPngTag=Date FILENAME

I have to ask the obvious, is the file you're testing a PNG file?

Add this line as the very first line
print "Found Config file\n";

This will cause exiftool to print a line indicating it is using the config file whenever it is run.
* 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).

Velmonte

...I just checked, and it is not a PNG. It's a JPG. At this point, would I change the config file code to make JPG tags, or could I just convert the existing JPGs into PNGs?

StarGeek

"NewPngTag" would only work on PNG files, nothing else.

I would suggest making your new tags in the XMP namespace.  It's much simpler and more person friendly.  Also XMP works in just about any image file as well as others (MP4/Mov, PDF).  You can search these forums for plenty of examples (Google search).

But always remember, if you're creating new tags, it's quite unlikely that you'll find programs that will read them.
* 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).

Velmonte

So the custom tags would still be in XMP? For instance, "NewXmpTag", so they'd be compatible with different photo types?

StarGeek

Quote from: Velmonte on September 08, 2021, 03:20:31 PM
So the custom tags would still be in XMP?

Your example above was attempting to use a PNG tag, not an XMP tag. Which is why I'm suggesting creating an XMP tag instead.  In the example config file, look at the 8-10 examples, XMP-xxx:NewXMPxxxTag1 through XMP-xxx:NewXMPxxxTag3.
* 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).

Velmonte

Here is the section I'm looking at in the example.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' },
    # Example 11.  XMP-xxx:NewXMPxxxStruct (a structured tag)
    # - 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)
            # --> multiple entries may exist in this namespace lookup,
            # with the last one alphabetically being the default for
            # the fields, but each field may have a "Namespace"
            # element to specify which prefix to use
            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 fields (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 a corresponding flattened tag that is
    # generated automatically with an ID made from a 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.
    # The "Flat" flag must be used when setting the Name or Description of a
    # flattened tag.  For example:
    NewXMPxxxStructX => { Name => 'SomeOtherName', Flat => 1 },

Am I supposed to just alter the parameters in the different groups?

StarGeek

That is the section to look at.  Read the notes for more details

Here's an extremely basic template for XMP tags. These tags are simple strings.  Replace "MyTag#" with the names you actually want to call the tags.  Repeat for each tag name.  You can add details like groups or change them from simple strings to something else by adding details between the braces.

Save this to a file and call it with the -Config option or save it as your .exiftool_config file.

%Image::ExifTool::UserDefined = (
'Image::ExifTool::XMP::xmp' => {
MyTag1 => { },
MyTag1 => { },
},
);
1;
* 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).

Velmonte

Thank you! Could I use this snippet in my own config file and just use it as my ".ExifTool_config" file instead (leaving out everything else in the sample config)? Also, when you say to add print "Found Config file\n"; as the first line, did you mean in the command prompt or in the config file itself?

StarGeek

Quote from: Velmonte on September 15, 2021, 03:32:49 PM
Thank you! Could I use this snippet in my own config file and just use it as my ".ExifTool_config" file instead

Yes, you can remove the original completely and replace it with this.  If you want to combine the two, that's more complicated.

QuoteAlso, when you say to add print "Found Config file\n"; as the first line, did you mean in the command prompt or in the config file itself?

In the config file itself, but I only suggested that to see if exiftool was finding your config file.  It's not something you want to keep in the file.
* 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).

Velmonte

#12
So I ended up creating my own config file as a .txt using the snippet you suggested. However, my exiftool is still not finding it. I placed the file in the same directory that my exiftool app is in (Windows folder). Below is the command I'm attempting to use.

exiftool -config C:\Windows\PoleEXIF.config.txt Date="test" UniqueID="test" PoleNumber="test" EquipmentType="test" Issue="test" Substation="test" Circuit="test" RiskLevel="test" StaticImagePath="test" VideoPath="test" FuturePrediction="test" Status="test" FILENAME

Thank you for all your help so far.

Phil Harvey

Why do you say that exiftool can't find it?  What is the exact message?

And maybe attach your config file so we can be sure it is OK.

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

Velmonte

I actually just got it to work using this command. I only forgot to add the hyphens before each tag.

exiftool -config C:\Windows\PoleEXIF.cfg.txt -Date=" " -UniqueID=" " -PoleNumber=" " -EquipmentType=" " -Issue=" " -Substation=" " -Circuit=" " -RiskLevel=" " -StaticImagePath=" " -VideoPath=" " -FuturePrediction=" " -Status=" " FILENAME

Though I still only see the tags when querying the images via the command line. Is there anyway to make custom tags visible in the windows Properties -> Details tab of images?