ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Allen B. Taylor on October 21, 2010, 05:43:43 PM

Title: Adding XMP lists and structure
Post by: Allen B. Taylor on October 21, 2010, 05:43:43 PM
I need to add new tags definitions, so I'm trying to define a configuration file for the tags I need. I need a structure that can contain a list of structures in it. Here's an example of the RDF I'd like to see. Each image (.jp2 file) can have a single color and multiple light sources, each with an ID and a temperature:

<rdf:Description rdf:about=''
  xmlns:temmi='http://mdacorporation.com/temmi/1.0/'>
  xmlns:temmi-l='http://mdacorporation.com/temmi/1.0/lighting'>
  xmlns:temmi-ls='http://mdacorporation.com/temmi/1.0/lightingSource'>
  <temmi:Lighting rdf:parseType='Resource'>
   <temmi-l:Color>red</temmi-l:Color>
   <rdf:Seq>
    <rdf:Description rdf:about=''
     xmlns:temmi-l='http://mdacorporation.com/temmi/1.0/lighting/'>
     <temmi-ls:ID>1</temmi-ls:ID>
     <temmi-ls:Temperature>22.2</temmi-ls:Temperature>
    </rdf:Description>
    <rdf:Description rdf:about=''
     xmlns:temmi-l='http://mdacorporation.com/temmi/1.0/lighting/'>
     <temmi-ls:ID>2</temmi-ls:ID>
     <temmi-ls:Temperature>23.1</temmi-ls:Temperature>
    </rdf:Description>
   </rdf:Seq>
  </temmi:LightingSourceID>
</rdf:Description>

How do I define this in the config file, and then how do I issue the commands from the command line?
Title: Re: Adding XMP lists and structure
Post by: Phil Harvey on October 21, 2010, 07:29:36 PM
Hi Allan,

I always hate it when someone asks about XMP structures because they are currently a real pain, but I will do my best to help you with this.

I'm not sure if the structure you propose is valid because you have a sequence of structures (the LightingSource stuctures) which aren't named, but you can come close to what you want with a config file like this:

%Image::ExifTool::UserDefined = (
   'Image::ExifTool::XMP::Main' => {
       temmi => {
           SubDirectory => {
               TagTable => 'Image::ExifTool::UserDefined::temmi',
           },
       },
   },
);

%Image::ExifTool::UserDefined::temmi = (
   GROUPS    => { 0 => 'XMP', 1 => 'XMP-temmi', 2 => 'Image' },
   NAMESPACE => { 'temmi' => 'http://mdacorporation.com/temmi/1.0/' },
   WRITABLE  => 'string',
   Lighting => {
       SubDirectory => { },  # prevents this tag being directly writable
       Struct => 'Lighting', # arbitrary name identifies entry in xmpStruct
   },
   # structure elements must be defined as separate tags.  The tag ID's
   # are the concatination of the structure tag ID with the ID of each
   # structure element in turn.  The list flag should be set if the
   # parent structure is contained in a list.
   LightingColor => { },
   LightingSource => {
       SubDirectory => { },
       Struct => 'LightingSource',
   },
   LightingSourceId => {
       Name => 'LightingSourceID',
       List => 1,
       Writable => 'integer',
   },
   LightingSourceTemperature => {
       List => 1,
       Writable => 'real',
   },
);

# User-defined XMP structures are added to the xmpStruct lookup
%Image::ExifTool::UserDefined::xmpStruct = (
   Lighting => {
       NAMESPACE => { 'temmi-l' => 'http://mdacorporation.com/temmi/1.0/lighting' },
       Color => { },
       Source => {
           Struct => 'LightingSource',
           List => 'Seq',
       },
   },
   LightingSource => {
       NAMESPACE => { 'temmi-ls' => 'http://mdacorporation.com/temmi/1.0/lightingSource' },
       ID => { },
       Temperature => { }
   },
);

1;  #end


which works like this:

exiftool a.xmp -lightingcolor=red -lightingsourceid=1 -lightingsourcetemperature=22.2 -lightingsourceid=2 -lightingsourcetemperature=23.1


and produces XMP like this:

<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>
<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Image::ExifTool 8.35'>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about=''
 xmlns:temmi='http://mdacorporation.com/temmi/1.0/'
 xmlns:temmi-l='http://mdacorporation.com/temmi/1.0/lighting'
 xmlns:temmi-ls='http://mdacorporation.com/temmi/1.0/lightingSource'>
 <temmi:Lighting rdf:parseType='Resource'>
  <temmi-l:Color>red</temmi-l:Color>
  <temmi-l:Source>
   <rdf:Seq>
    <rdf:li rdf:parseType='Resource'>
     <temmi-ls:ID>1</temmi-ls:ID>
     <temmi-ls:Temperature>22.2</temmi-ls:Temperature>
    </rdf:li>
    <rdf:li rdf:parseType='Resource'>
     <temmi-ls:ID>2</temmi-ls:ID>
     <temmi-ls:Temperature>23.1</temmi-ls:Temperature>
    </rdf:li>
   </rdf:Seq>
  </temmi-l:Source>
 </temmi:Lighting>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?>


- Phil
Title: Re: Adding XMP lists and structure
Post by: Allen B. Taylor on October 22, 2010, 09:45:11 AM
Phil,

This is exactly what I'm looking for. I just couldn't figure out how to code the config file. It was close, but just not working.

Perhaps some examples of this could be added to the sample config file. That would have helped me out.

Many thanks for the help.

Allen
Title: Re: Adding XMP lists and structure
Post by: Phil Harvey on October 22, 2010, 11:41:49 AM
Hi Allen,

I'm glad this helped.

Thanks for the suggestion, but the config file is already too confusing for most people.  I recommend looking at the XMP source code (XMP.pm, XMP2.pm and WriteXMP.pl) if you want lots of examples.  Also, lib/Image/ExifTool/README explains lots of things you probably don't want to know about. :)

Tags are defined in the source code in basically the same way as in the config file.

- Phil
Title: Re: Adding XMP lists and structure
Post by: Phil Harvey on January 23, 2011, 10:38:01 AM
Although the config file shown in the previous post will should still work, the definition of user-defined structures has been simplified as of ExifTool version 8.46.  The corresponding config file now looks like this:

%Image::ExifTool::UserDefined = (
  'Image::ExifTool::XMP::Main' => {
    temmi => {
      SubDirectory => {
        TagTable => 'Image::ExifTool::UserDefined::temmi',
      },
    },
  },
);

%Image::ExifTool::UserDefined::temmi = (
  GROUPS    => { 0 => 'XMP', 1 => 'XMP-temmi', 2 => 'Image' },
  NAMESPACE => { 'temmi' => 'http://mdacorporation.com/temmi/1.0/' },
  WRITABLE  => 'string',
  Lighting => {
    Struct => {
      # NAMESPACE is required...
      NAMESPACE => { 'temmi-l' => 'http://mdacorporation.com/temmi/1.0/lighting' },
      # STRUCT_NAME is optional, and used only for warning messages...
      STRUCT_NAME => 'Lighting',
      Color => { },
      Source => {
        Struct => {
          NAMESPACE => { 'temmi-ls' => 'http://mdacorporation.com/temmi/1.0/lightingSource' },
          STRUCT_NAME => 'LightingSource',
          ID => { },
          Temperature => { },
        },
        List => 'Seq',
      },
    },
  },
);

1;  #end


See the config file documentation (https://exiftool.org/config.html) for details.

- Phil