ExifTool Forum

General => Metadata => Topic started by: povette on June 12, 2017, 12:24:17 AM

Title: swapping around IPTC metadata in JPEG files
Post by: povette on June 12, 2017, 12:24:17 AM
I have a number of JPEG files of which I would like swap their IPTC metadata into different fields, before importing them into Aperture on macOS.

File: https://www.flickr.com/photos/107131447@N06/34130923753/in/pool-47207227@N00

This file, when downloaded, will contain the following IPTC metadata:

• Caption/Description: Found these minifigs and a lot of classic space parts ( not all shown because It's to many!!!) on a fleamarket last week. I was so happy to find the spaceship spaceship!!! from the 924 set because i always wanted that ship when i was a kid and after all t...

• Copyright Notice: Item by okoe74 - https://www.flickr.com/photos/107131447@N06/34130923753

• Keywords: legoclassicspaceloot, flickr

• Title: Lego classic space loot!!!


I have the following arguments in the ".ExifTool_config" in my Home directory:

%Image::ExifTool::UserDefined = (
    # Composite tags are added to the Composite table:
    'Image::ExifTool::Composite' => {
        BaseName => {
            Require => {
                0 => 'FileName',
            },
            # remove the extension from FileName
            ValueConv => '$val[0] =~ /(.*)\./ ? $1 : $val[0]',
        },
        MyTag => {
            Require => {
                0 => 'Caption-Abstract',
            },
            ValueConv => 'substr($val, 20)',
        },
        MyTag2 => {
            Require => {
                0 => 'CopyrightNotice',
            },
            ValueConv => 'substr($val, 8)',
        },
    },
);

1; #end




Using the following command I expect the following: "exiftool "-iptc:headline<basename" "-iptc:keywords=" "-caption-abstract<mytag" "-iptc:credit<mytag2" "-iptc:CopyrightNotice=" ~/DIR"

• Copy the filename ("basename") to the "Headline" field without the file extension.

• Delete all of the Keywords.

• Temporarily copy the Caption data into a temporary location to remove the first twenty unnecessary characters and then copy it into the "Caption" field.

• Temporarily copy the CopyrightNotice data into a temporary location to remove the first eight unnecessary characters and then copy it into the "Provider" field.



While all of the Keywords data is successfully removed and the Caption data is correctly copied over and the first twenty characters removed, the filename (baseline) data seems to keep finding it's way into the "IPTC:Title" field and not the "IPTC:Headline" field, while the CopyrightNotice will not show up at all in the "IPTC:Provider" field for some reason?


(http://i.imgur.com/nEJ2ewM.png)


I tried reordering the command to put the data into the "mytag2" temporary container first and then into the desired field, but it did not work: "-iptc:headline<basename" "-iptc:keywords=" "-caption-abstract<mytag" "-CopyrightNotice<mytag2" "-iptc:credit<mytag2"
Title: Re: swapping around IPTC metadata in JPEG files
Post by: StarGeek on June 12, 2017, 01:35:40 AM
This is probably a FAQ 3 (http://www.exiftool.org/faq.html#Q3) question. 

It's apparent that what Aperture calls Headline, Title, and Provider don't map to the tags you think they do.  Are you able to type into those fields and save it to a test file?  If so, save some unique values and then use exiftool -g1 -a -s to see what tags those values were actually saved to.
Title: Re: swapping around IPTC metadata in JPEG files
Post by: povette on June 12, 2017, 08:53:07 AM
Yes, that's right and it's a very useful command. I now find that "BaseName" was in fact "FileName" and the following works to copy over the file name and scrub the "Title" (ObjectName) field:

exiftool "-iptc:headline<filename" "-iptc:objectname="


However, I'm now having trouble with the CopyrightNotice property which I would like to pass into the following argument to trim off some characters, but cannot assign it to the IPTC:Credit field, only itself:

        MyTag2 => {
            Require => {
                0 => 'CopyrightNotice',
            },
            ValueConv => 'substr($val, 8)',
        },



e.g. The following will not work:

exiftool "-iptc:copyrightnotice<mytag2" "-iptc:credit<copyrightnotice"
Title: Re: swapping around IPTC metadata in JPEG files
Post by: Phil Harvey on June 12, 2017, 09:59:11 AM
Quote from: povette on June 12, 2017, 08:53:07 AM
e.g. The following will not work:

exiftool "-iptc:copyrightnotice<mytag2" "-iptc:credit<copyrightnotice"

There are 2 reasons why this might not work:

1. iptc:coyrightnotice doesn't already exist in the file

2. your config file isn't getting loaded properly (see FAQ 11 (https://exiftool.org/faq.html#Q11))

But using the advanced formatting feature, a user-defined tag isn't necessary, so you wouldn't need the config file with this command:

exiftool "-iptc:copyrightnotice<${copyrightnotice;$_=substr($_,8)}" "-iptc:credit<copyrightnotice" FILE

- Phil

Title: Re: swapping around IPTC metadata in JPEG files
Post by: povette on June 12, 2017, 03:36:53 PM
I confirmed the config file was being loaded as "LOADED!" was printed when in use, I knew that the config file must have loaded because the custom "mytag" was working (replacing the same metadata, but with 20 chars less) for the Caption-Abstract IPTC field.

The command I already use is complicated enough, so I wanted a as much hidden inside the config file, for ease of use, as possible.

I can get the CopyrightNotice metadata to copy into the IPTC:Credit field, but with a truncation error (limiting it to only 32 chars):

"Item by okoe74 - https://www.flickr.com/photos/107131447@N06/34130923753" becomes "Item by okoe74 - https://www.fli"

But it crucially does not lop off the first eight chars, unlike with the Caption-Abstract field. I don't know if it's because the temporary metadata in the custom "MyTag2" variable is wiped as it moves on to another command ("-iptc:credit<copyrightnotice")? My understanding was that the data would have been replaced in CopyrightNotice and so copying it would be that amended version, not the original.
Title: Re: swapping around IPTC metadata in JPEG files
Post by: StarGeek on June 12, 2017, 04:14:46 PM
Quote from: povette on June 12, 2017, 03:36:53 PM
I can get the CopyrightNotice metadata to copy into the IPTC:Credit field, but with a truncation error (limiting it to only 32 chars):

The IPTC standard for that field has a 32 character limit (see IPTC tags (http://www.exiftool.org/TagNames/IPTC.html) for details).  You can tell exiftool to ignore that limit with the -m option.  You'll have to test to see if Aperture can handle the longer field.
Title: Re: swapping around IPTC metadata in JPEG files
Post by: povette on June 12, 2017, 05:55:00 PM
Thanks. That comment was something that I could have looked up, I added it just because it was a result of the rest of the issues at the time.

The -m operator worked as expected. Aperture can handle a lot of metadata in any field.

Many thanks!

After closing down Terminal and using different pictures as test examples, I find now that everything works!