Reading and writing by IPTC tag ID

Started by yosh, November 06, 2014, 11:52:20 AM

Previous topic - Next topic

yosh

Hello,

I have two questions regarding IPTC handling via Perl library. I need to read, edit and write IPTC. It doesn't really matter if XMP gets written too.

1. Is it possible to read (and write) IPTC records based on numeric IPTC Tag ID? Something like $exifTool->SetValue('IPTC:2.80', 'John Smith')

2. Can I assume that all not listed IPTC Application Tags have names like IPTC_ApplicationRecord_# and use these names to insert custom records?

Thanks in advance! :)

Phil Harvey

Quote from: yosh on November 06, 2014, 11:52:20 AM
1. Is it possible to read (and write) IPTC records based on numeric IPTC Tag ID? Something like $exifTool->SetValue('IPTC:2.80', 'John Smith')

No.  You must use a tag name.  If the tag is not defined, you must create a user-defined tag to write it.  See the sample config file for an example.

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

yosh

Thanks. Added user-defined tags to .ExifTool_config and I get them with $Image::ExifTool::IPTC::ApplicationRecord{$number}->{Name} where $number is IPTC field number, i.e. 105.

Different question... Hope it's ok to use the same topic.

Is there a way to read metadata from one file and save it to several new JPEG files, each made with source picture data, but with different metadata modifications?

At the moment, for every destination file I create new my $exifTool = Image::ExifTool->new;, add/delete metadata and save to new location. This way, for every destination file I get original source metadata, without modifications made in previous iterations (for previously handled destinations). It would be ideal to create $exifTool just once and then replicate metadata table for every new file. It seems that such solution would be a lot more lightweight than mine. Is there a way to do it that way?

Phil Harvey

You don't need to replicate the ExifTool object.  Just call WriteInfo repeatedly for each file you want to write the tags to.  You don't need to set the new values again between these calls.  eg)

$exiftool->SetNewValuesFromFile(...);
$exiftool->WriteInfo($file1);
$exiftool->WriteInfo($file2);
...


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

yosh

#4
The problem is I need different modifications for each destination image, so that each output file works on base metadata and not metadata edited with previous iteration. Example:

my $exifTool = Image::ExifTool->new;
my $info = $exifTool->ImageInfo($source_file);
foreach (@output_file)
{
     my $deleteAuthor = &GetSettingForThisOutput($_);
     if ($deleteAuthor eq 1) {
          $exifTool->SetNewValue('By-line');
     }
     $exiftool->WriteInfo($source_file, $_);
}


Let's say:
- Settings for 1st output file say that author (By-line) should be deleted
- Settings for 2nd output file say author shouldn't be changed
The above code obviously results in two files without By-line value.

Normally, I would create local variable holding the copy of metadata object, modify it accordingly to settings and use it along the source picture data to create new output file. Is something like this possible?

Sorry if this is some trivial problem. Just can't find solution and Perl is not my native language :)

EDIT:

I think I've misunderstood your reply before. I've now changed the code and it seems to work without creating new $exifTool object. It's now something like:

my $exifTool = Image::ExifTool->new;
foreach (@outputFile)
{
    $exifTool->SetNewValuesFromFile($sourceFile, 'IPTC:*');

     my $deleteAuthor = &GetSettingForThisOutput($_);
     if ($deleteAuthor eq 1) {
          $exifTool->SetNewValue('By-line');
     }
     $exiftool->WriteInfo($sourceFile, $_);
}


Too bad that the source file has to be scanned again.


Phil Harvey

Ah. So you want to maintain a number of separate sets of metadata edits.  Yes, you can do this with separate ExifTool objects.

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