Project

General

Profile

XMP struct tags

Added by Mikayel Egibyan over 6 years ago

Hi,

Is there any way to extract structural tag values at the time?

e.g. xmpData["Xmp.xmpMM.DerivedFrom/stRef:instanceID"], xmpData["Xmp.xmpMM.DerivedFrom/stRef:..."], ...

Instead of doing all this things separately to do something like xmpData["Xmp.xmpMM.DerivedFrom/stRef:ALL"] or xmpData["Xmp.xmpMM.DerivedFrom..."] to get {*istanceID, ..., *...} values?

Any help is appreciated.
Thanks,
Mikayel


Replies (11)

RE: XMP struct tags - Added by Robin Mills over 6 years ago

Mikayel

Benjamin recently asked about this topic. Regrettably, I couldn't help him. However perhaps you and Benjamin can cooperate to solve this puzzle - and share the solution with the world. That's how open source works. http://dev.exiv2.org/boards/3/topics/1871

Alan (Pater) asked recently about converting ACDE "Category" xml tags into LightRoom Hierarchies. I was able to give him a solution to that by using some Perl to reformat the ACDE xml into LR tags. I think this is a little different from your question. However my solution shows how to use external tools such as Perl and XMLlint (which includes an XPath evaluator). http://dev.exiv2.org/boards/3/topics/1912

Good Luck

Robin

RE: XMP struct tags - Added by Robin Mills over 6 years ago

One other thought about this. In the discussion with Benjamin (1871), I referred him to some code to extract the raw XML from the image file using the formidable 'dd' utility (dd == deadly dangerous). It's probably better to locate the raw xml data from the image and use XPath or something to navigate the dom.

http://dev.exiv2.org/boards/3/topics/1608?r=1624#message-1624

Perhaps that helps. Perhaps not. If you find a solution, please share.

RE: XMP struct tags - Added by Robin Mills over 6 years ago

I have added a new option to exiv2(.exe) -pX to extract the XMP block from an image. With this option, you can easily extract the xml and process it with xmllint, perl, python, xslt or any external tool. r3650

RE: XMP struct tags - Added by Robin Mills over 6 years ago

I've had a little think about this. I've used the new exiv2 -pX option to extract the XMP from BabyGnuTux-BigWLPG.jpg:

<?xml version="1.0"?>
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.0-c060 61.134777, 2010/02/12-17:32:00        ">
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/" xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#" rdf:about="" xmp:CreatorTool="Adobe Photoshop CS5 Windows" xmp:CreateDate="2012-01-04T20:32:52+01:00" xmp:ModifyDate="2012-01-04T20:34:45+01:00" xmp:MetadataDate="2012-01-04T20:34:45+01:00" dc:format="image/jpeg" photoshop:ColorMode="3" photoshop:ICCProfile="sRGB IEC61966-2.1" xmpMM:InstanceID="xmp.iid:4E9C1E280B37E111A568FF94F417581A" xmpMM:DocumentID="xmp.did:4D9C1E280B37E111A568FF94F417581A" xmpMM:OriginalDocumentID="xmp.did:4D9C1E280B37E111A568FF94F417581A">
      <xmpMM:History>
        <rdf:Seq>
          <rdf:li stEvt:action="created" stEvt:instanceID="xmp.iid:4D9C1E280B37E111A568FF94F417581A" stEvt:when="2012-01-04T20:32:52+01:00" stEvt:softwareAgent="Adobe Photoshop CS5 Windows"/>
          <rdf:li stEvt:action="converted" stEvt:parameters="from image/png to image/jpeg"/>
          <rdf:li stEvt:action="saved" stEvt:instanceID="xmp.iid:4E9C1E280B37E111A568FF94F417581A" stEvt:when="2012-01-04T20:34:45+01:00" stEvt:softwareAgent="Adobe Photoshop CS5 Windows" stEvt:changed="/"/>
        </rdf:Seq>
      </xmpMM:History>
    </rdf:Description>
    <rdf:Description xmlns:MP="http://ns.microsoft.com/photo/1.2/">
      <MP:RegionInfo>
        <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
          <MPRI:Regions xmlns:MPRI="http://ns.microsoft.com/photo/1.2/t/RegionInfo#">
            <rdf:Bag xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
              <rdf:li>
                <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
                  <MPReg:Rectangle xmlns:MPReg="http://ns.microsoft.com/photo/1.2/t/Region#">0.661608, 0.244310, 0.130501, 0.261002</MPReg:Rectangle>
                  <MPReg:PersonDisplayName xmlns:MPReg="http://ns.microsoft.com/photo/1.2/t/Region#">Baby Tux</MPReg:PersonDisplayName>
                </rdf:Description>
              </rdf:li>
              <rdf:li>
                <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
                  <MPReg:Rectangle xmlns:MPReg="http://ns.microsoft.com/photo/1.2/t/Region#">0.205615, 0.226100, 0.130501, 0.261002</MPReg:Rectangle>
                  <MPReg:PersonDisplayName xmlns:MPReg="http://ns.microsoft.com/photo/1.2/t/Region#">Baby Gnu</MPReg:PersonDisplayName>
                </rdf:Description>
              </rdf:li>
            </rdf:Bag>
          </MPRI:Regions>
        </rdf:Description>
      </MP:RegionInfo>
    </rdf:Description>
  </rdf:RDF>
</x:xmpmeta>
<?xpacket end='w'?>
I used samples/exiv2json to format the xmp metadata from an image and it revealed:
    "Xmp": {
        "xmp": {
            "CreatorTool": "Adobe Photoshop CS5 Windows",
            "CreateDate": "2012-01-04T20:32:52+01:00",
            "ModifyDate": "2012-01-04T20:34:45+01:00",
            "MetadataDate": "2012-01-04T20:34:45+01:00" 
        },
        "dc": {
            "format": "image\/jpeg" 
        },
        "photoshop": {
            "ColorMode": "3",
            "ICCProfile": "sRGB IEC61966-2.1" 
        },
        "xmpMM": {
            "InstanceID": "xmp.iid:4E9C1E280B37E111A568FF94F417581A",
            "DocumentID": "xmp.did:4D9C1E280B37E111A568FF94F417581A",
            "OriginalDocumentID": "xmp.did:4D9C1E280B37E111A568FF94F417581A",
            "History": "type=\"Seq\"",
            "History[1]": "type=\"Struct\"",
            "History[1]/stEvt:action": "created",
            "History[1]/stEvt:instanceID": "xmp.iid:4D9C1E280B37E111A568FF94F417581A",
            "History[1]/stEvt:when": "2012-01-04T20:32:52+01:00",
            "History[1]/stEvt:softwareAgent": "Adobe Photoshop CS5 Windows",
            "History[2]": "type=\"Struct\"",
            "History[2]/stEvt:action": "converted",
            "History[2]/stEvt:parameters": "from image\/png to image\/jpeg",
            "History[3]": "type=\"Struct\"",
            "History[3]/stEvt:action": "saved",
            "History[3]/stEvt:instanceID": "xmp.iid:4E9C1E280B37E111A568FF94F417581A",
            "History[3]/stEvt:when": "2012-01-04T20:34:45+01:00",
            "History[3]/stEvt:softwareAgent": "Adobe Photoshop CS5 Windows",
            "History[3]/stEvt:changed": "\/" 
        },
        "MP": {
            "RegionInfo": "type=\"Struct\"",
            "RegionInfo/MPRI:Regions": "type=\"Bag\"",
            "RegionInfo/MPRI:Regions[1]": "type=\"Struct\"",
            "RegionInfo/MPRI:Regions[1]/MPReg:Rectangle": "0.661608, 0.244310, 0.130501, 0.261002",
            "RegionInfo/MPRI:Regions[1]/MPReg:PersonDisplayName": "Baby Tux",
            "RegionInfo/MPRI:Regions[2]": "type=\"Struct\"",
            "RegionInfo/MPRI:Regions[2]/MPReg:Rectangle": "0.205615, 0.226100, 0.130501, 0.261002",
            "RegionInfo/MPRI:Regions[2]/MPReg:PersonDisplayName": "Baby Gnu" 
        }
    }
I looked at this and manually compiled it into this:
"xmp": {
    "CreatorTool": "Adobe Photoshop CS5 Windows",
    "CreateDate": "2012-01-04T20:32:52+01:00",
    "ModifyDate": "2012-01-04T20:34:45+01:00",
    "MetadataDate": "2012-01-04T20:34:45+01:00" 
},
"dc": {
    "format": "image\/jpeg" 
},
"photoshop": {
    "ColorMode" : "3",
    "ICCProfile": "sRGB IEC61966-2.1" 
},
"xmpMM": {
    "InstanceID": "xmp.iid:4E9C1E280B37E111A568FF94F417581A",
    "DocumentID": "xmp.did:4D9C1E280B37E111A568FF94F417581A",
    "OriginalDocumentID": "xmp.did:4D9C1E280B37E111A568FF94F417581A",
    "History": [
        { "stEvt": {
            "action": "created",
            "instanceID": "xmp.iid:4D9C1E280B37E111A568FF94F417581A",
            "when": "2012-01-04T20:32:52+01:00",
            "softwareAgent": "Adobe Photoshop CS5 Windows" 
        } },
        "stEvt" : {
            "action": "converted",
            "parameters": "from image\/png to image\/jpeg" 
        } },
        { "stEvt" : {
           "action": "saved",
           "instanceID": "xmp.iid:4E9C1E280B37E111A568FF94F417581A",
           "when": "2012-01-04T20:34:45+01:00",
           "softwareAgent": "Adobe Photoshop CS5 Windows",
           "changed": "\/" 
        } }
    ]
},
"MP": {
    "RegionInfo": {
        "MPRI" {
            Regions": [
                   "MPReg" {
                    "Rectangle": "0.661608, 0.244310, 0.130501, 0.261002",
                    "PersonDisplayName": "Baby Tux" 
                } ,
                   "MPReg" {
                    "Rectangle": "0.205615, 0.226100, 0.130501, 0.261002",
                    "PersonDisplayName": "Baby Gnu" 
                }
            ]
        }
    }
}

A Struct -> a JSON object { ... }. A Seq (or Alt or Bag) -> a JSON array [ .... ]. I've half written the code to do this automatically. However I'm going on vacation for 2 weeks and don't have time to finish and submit the code. This isn't difficult and I am sure you can do this for yourself in an afternoon.

RE: XMP struct tags - Added by Mikayel Egibyan over 6 years ago

Can you please attach the updated version?

Thanks,
Mikayel

RE: XMP struct tags - Added by Robin Mills over 6 years ago

You're out of luck, Mikayel. I didn't finish it at the weekend and now I'm on vacation. However I did submit the code with the exiv2(.exe) -pX option to extract the XMP "raw" xml which you can process with various tools of course.

RE: XMP struct tags - Added by Robin Mills over 6 years ago

Mikayel

The code is more tricky than I thought. I'm making progress. I've updated the notes above concerning the manual compilation. I'm using those notes to help me debug this. Patience .....................

Robin

RE: XMP struct tags - Added by Robin Mills over 6 years ago

Right. I've got the code working. Much harder than I expected. I don't want to submit yet because I'm on vacation and I'd like to review the code to see if it can be simplified. Here's the output:

  "Xmp": {
    "xmp": {
      "CreatorTool": "Adobe Photoshop CS5 Windows",
      "CreateDate": "2012-01-04T20:32:52+01:00",
      "ModifyDate": "2012-01-04T20:34:45+01:00",
      "MetadataDate": "2012-01-04T20:34:45+01:00" 
    },
    "dc": {
      "format": "image\/jpeg" 
    },
    "photoshop": {
      "ColorMode": "3",
      "ICCProfile": "sRGB IEC61966-2.1" 
    },
    "xmpMM": {
      "InstanceID": "xmp.iid:4E9C1E280B37E111A568FF94F417581A",
      "DocumentID": "xmp.did:4D9C1E280B37E111A568FF94F417581A",
      "OriginalDocumentID": "xmp.did:4D9C1E280B37E111A568FF94F417581A",
      "History": [
        {
          "stEvt": {
            "action": "created",
            "instanceID": "xmp.iid:4D9C1E280B37E111A568FF94F417581A",
            "when": "2012-01-04T20:32:52+01:00",
            "softwareAgent": "Adobe Photoshop CS5 Windows" 
          }
        },
        {
          "stEvt": {
            "action": "converted",
            "parameters": "from image\/png to image\/jpeg" 
          }
        },
        {
          "stEvt": {
            "action": "saved",
            "instanceID": "xmp.iid:4E9C1E280B37E111A568FF94F417581A",
            "when": "2012-01-04T20:34:45+01:00",
            "softwareAgent": "Adobe Photoshop CS5 Windows",
            "changed": "\/" 
          }
        }
      ]
    },
    "MP": {
      "RegionInfo": {
        "MPRI": {
          "Regions": [
            {
              "MPReg": {
                "Rectangle": "0.661608, 0.244310, 0.130501, 0.261002",
                "PersonDisplayName": "Baby Tux" 
              }
            },
            {
              "MPReg": {
                "Rectangle": "0.205615, 0.226100, 0.130501, 0.261002",
                "PersonDisplayName": "Baby Gnu" 
              }
            }
          ]
        }
      }
    }
  }
When the data has been parsed into this format, you can navigate it in C++ using Jzon without having to serialize. Of course, you can serialize and read it into your favorite JSON reader.

RE: XMP struct tags - Added by Robin Mills over 6 years ago

Submitted: r3666. I've also logged a feature request to deal with this: #1054.

RE: XMP struct tags - Added by Mikayel Egibyan over 6 years ago

Thank you Robin,

Can you please attach the file with source?

Thank you once more,
Mikayel

RE: XMP struct tags - Added by Robin Mills over 6 years ago

Mikayel

You can get the code from svn:
$ svn export svn://dev.exiv2.org/svn/trunk/samples/exiv2json.cpp

If you don't have an SVN client, I highly recommend Tortoise on Windows. I use SmartSVN on Mac/Linux/Windows - and the command-line.

    (1-11/11)