add custom XMP tags to JPGS (perl lib)

Started by Archive, May 12, 2010, 08:54:15 AM

Previous topic - Next topic

Archive

[Originally posted by a666 on 2008-02-20 10:42:25-08]

hello,

i am new here and a little bit lost when it comes to write out meta info to jpgs. so far i have no problems reading information, nor do i when setting individual new values.

but now i need to store custom information where no tags are defined for. someone suggested adding an own namespace within the XMP block. can this be done with exiftool directly (i mean without working with SetNewValuesFromFile) and possibly with the ExifTool Perl Library Module?

tags i'd like to add:

- some text strings > 2000 chars

- some boolean values (i know XMP is text, but anyhow...)

some code examples would be greatly appreciated!

other question: are text strings in XMP limited in length? IPTC tags are by specification, so what about the IPTC block inside XMP?

thanks and greetings from Tyrol/Austria
andré

Archive

[Originally posted by exiftool on 2008-02-20 11:41:15-08]

Hi André,

See the https://exiftool.org/config.html" target="_blank">config
file documentation for examples of how to add user-defined
XMP tags (it also has an example of how to add a new
namespace).

XMP values have no limit on line length, although if written to a JPEG
image, there is a limit of 64 kB on the XMP segment since the XMP
specification doesn't allow it to span multiple JPEG segments.

As far as boolean values goes, XMP actually has a boolean data
type.  Read the https://exiftool.org/TagNames/XMP.html" target="_blank">XMP
tag documentation for details.

- Phil

Archive

[Originally posted by a666 on 2008-02-20 16:04:30-08]

hi phil,

thank you for the links!

i managed to add info with the config file and the standalone exiftool.exe from the command line and that shows up in photoshop.

but i am puzzled about doing the same with the perl lib alone. this doesn't generate errors but it doesn't work:

Code:
use Image::ExifTool;
my $exifTool = new Image::ExifTool;
$exifTool->SetNewValue('NewXMPxxxTag1' => 'xxxxxxxxxxxxx');
$exifTool->WriteInfo('i.jpg');

do i need to load something else?

note: .ExifTool_config (unmodified from your link) loads, "LOADED" prints out with

Code:
print "LOADED!\n";

thx,
andré

Archive

[Originally posted by exiftool on 2008-02-20 16:22:48-08]

Hi Andr&eacute,

Your script should work provided:

1) the config file is loaded properly.  (You tested this, so it should be OK)

2) the file "i.jpg" exists and is writable.

I suggest printing the return value from WriteInfo() (it should be 1 if
the file was changed), and checking for Errors and Warnings after
the call to WriteInfo():

Code:
$errorMessage = $exifTool->GetValue('Error');
$warningMessage = $exifTool->GetValue('Warning');

- Phil

Archive

[Originally posted by a666 on 2008-02-20 16:31:46-08]

okay, okay, stupid me.

was writing to i.jpg and reading from ii.jpg...

sorry for that and thank you for your quick advises!

andré

Archive

[Originally posted by a666 on 2008-02-20 18:13:28-08]

here a perl file that does it all without an .ExifTool_config file (reduced to XMP extension).

Code:

use Image::ExifTool;
my $exifTool = new Image::ExifTool;

# NEW XMP TAGS
%Image::ExifTool::UserDefined::geotraceNet = (
   GROUPS => { 0 => 'XMP', 1 => 'XMP-geotraceNet', 2 => 'Image' },
   NAMESPACE => { 'geotraceNet' => 'http://www.geotrace.net/ns/xmpext/1.0' },
   WRITABLE => 'string',
   PositionDescription => { },
   DestinationDescription => { },
   MainPhotoPointTitle => { },
);

# NEW XMP NAMESPACES MUST BE ADDED TO THE MAIN XMP TABLE
%Image::ExifTool::UserDefined = (
   'Image::ExifTool::XMP::Main' => {
      geotraceNet => {
         SubDirectory => {
            TagTable => 'Image::ExifTool::UserDefined::geotraceNet',
         },
      },
   },
);

$exifTool->SetNewValue('PositionDescription','blah PositionDescription');
$exifTool->SetNewValue('DestinationDescription','blah DestinationDescription');
$exifTool->SetNewValue('MainPhotoPointTitle','blah MainPhotoPointTitle');

$exifTool->WriteInfo('03.jpg');

Archive

[Originally posted by exiftool on 2008-02-20 18:55:58-08]

Nice.

You're quite correct to point out that the user-defined tags may
be added via the appropriate definitions in the main script.
I should probably document this.

Note that if you do it this way, any config file that exists is
effectively disabled because the definitions in your script will
override any definitions in the config file.  But that likely isn't
a concern here.

- Phil