Overriding existing IPTC date tags with a 'custom' format

Started by pluppens, September 03, 2021, 06:29:15 AM

Previous topic - Next topic

pluppens

Good day,

First of all: thank you, everyone, for an amazing tool and community. I'm not 100% sure this is the right board, so feel free to move the post if required.

I'm trying to work around a limitation in an application that is beyond my control. One of the quirks of that system is that is requires IPTC dates to be formatted in a 'yyyy-MM-dd' style, rather than the 'yyyyMMdd' digit[8] according to the standard.

To achieve this, I figured I'm supposed to rewrite the IPTC definitions using a custom config (assuming this is possible via Exiftool), and I did so as follows. I took the IDs using `exiftool -v3 <image>`.


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::IPTC::ApplicationRecord' => {
            0x0037 => {
                Name => 'DateCreated',
                Writable => 'string[10]'
            },
            0x001e => {
                Name => 'ReleaseDate',
                Writable => 'string[10]'
            },
            0x0025 => {
                Name => 'ExpirationDate',
                Writable => 'string[10]'
            },
        },
);


However, when I invoke this:
exiftool -config /path/to/.Exiftool_config.pl -IPTC:ExpirationDate=2021-09-16 -IPTC:DateCreated=2019-06-12 -IPTC:ReleaseDate=2021-09-04 /path/to/image

Then I get a reply saying the input is malformed:

Warning: Bad IPTC Format () for IPTC:ExpirationDate
Warning: Bad IPTC Format () for IPTC:DateCreated
Warning: Bad IPTC Format () for IPTC:ReleaseDate
Nothing to do.


Which tells me I might not be doing this correctly.

I would appreciate any input.

-Phil

StarGeek

This took me far to long to figure out, but then, it's not my area of expertise.

Your config file set the tags as Writable, but the example.config file shows that you need to use Format.  Also, you were missing some commas.

Try
%Image::ExifTool::UserDefined = (
'Image::ExifTool::IPTC::ApplicationRecord' => {
0x0037 => {
Name => 'DateCreated',
Format => 'string[10]',
},
0x001e => {
Name => 'ReleaseDate',
Format => 'string[10]',
},
0x0025 => {
Name => 'ExpirationDate',
Format => 'string[10]',
},
},
);


Example:
C:\>exiftool -config temp.config -P -overwrite_original -DateCreated=test y:\!temp\Test4.jpg
Warning: [Minor] String too short for IPTC:DateCreated (padded) - y:/!temp/Test4.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -datecreated y:\!temp\Test4.jpg
---- IPTC ----
DateCreated                     : test

* 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).

pluppens

Quote from: StarGeek on September 03, 2021, 11:59:36 AM
This took me far to long to figure out, but then, it's not my area of expertise.

Your config file set the tags as Writable, but the example.config file shows that you need to use Format.  Also, you were missing some commas.

I cannot believe I missed the `Format` key - I'm terribly sorry about that. As for the missing commas, I'll blame my non-Perl knowledge.

Quote from: StarGeek on September 03, 2021, 11:59:36 AM
Try
%Image::ExifTool::UserDefined = (
'Image::ExifTool::IPTC::ApplicationRecord' => {
0x0037 => {
Name => 'DateCreated',
Format => 'string[10]',
},
0x001e => {
Name => 'ReleaseDate',
Format => 'string[10]',
},
0x0025 => {
Name => 'ExpirationDate',
Format => 'string[10]',
},
},
);


Example:
C:\>exiftool -config temp.config -P -overwrite_original -DateCreated=test y:\!temp\Test4.jpg
Warning: [Minor] String too short for IPTC:DateCreated (padded) - y:/!temp/Test4.jpg
    1 image files updated

C:\>exiftool -g1 -a -s -datecreated y:\!temp\Test4.jpg
---- IPTC ----
DateCreated                     : test


Yes, it works like a charm! Thank you so much, StarGeek!

The only thing I can say is that it would be awesome to have some warnings displayed when using a config file via the CLI that is invalid, malformed or in my case, just random garbage. It might also not be a bad idea to add this as an example to the example config file (although one could argue it's never a good idea to promote 'bad practices').

Again, much appreciated!

StarGeek

Quote from: pluppens on September 04, 2021, 11:37:06 AM
The only thing I can say is that it would be awesome to have some warnings displayed when using a config file via the CLI that is invalid, malformed or in my case, just random garbage.

I doubt this is possible because a config file is just Perl code executed from within exiftool.  I'm guessing it's using the Perl eval function, so the whole program doesn't crash when the config has errors.
Quoteeval in all its forms is used to execute a little Perl program, trapping any errors encountered so they don't crash the calling program
* 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).

pluppens

Right - in that case, would adding the following at the top of the example file help? As I said before, I have no Perl knowledge, so I might be saying nonsense (esp. since there's no mention of it on the eval() documentation). Would there be a possibility to try/catch a Perl error when the config file is (obviously) malformed?


use strict;
use warnings FATAL => 'all';

StarGeek

Only Phil would be able to answer that and away for a couple of weeks.
* 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).

Phil Harvey

Quote from: pluppens on September 04, 2021, 11:37:06 AM
The only thing I can say is that it would be awesome to have some warnings displayed when using a config file via the CLI that is invalid, malformed or in my case, just random garbage.

I get warnings like this on MacOS:

> exiftool -config a.jpg a.jpg
Unrecognized character \xFF; marked by <-- HERE after <-- HERE near column 1 at a.jpg line 1.
ExifTool Version Number         : 12.31
File Name                       : a.jpg
Directory                       : .
File Size                       : 1392 KiB
File Modification Date/Time     : 2021:09:12 11:28:02-04:00
File Access Date/Time           : 2021:09:12 11:28:04-04:00
File Inode Change Date/Time     : 2021:09:12 11:28:02-04:00
File Permissions                : -rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Image Width                     : 1680
Image Height                    : 1050
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:4:4 (1 1)
Image Size                      : 1680x1050
Megapixels                      : 1.8


This should be a feature of the ExifTool code.  Here is the section of ExifTool.pm that loads the config file:

    unshift @INC, '.';      # look in current directory first
    eval { require $file }; # load the config file
    shift @INC;
    # print warning (minus "Compilation failed" part)
    $@ and $_=$@, s/Compilation failed.*//s, warn $_;


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