dragon66 / icafe

Java library for reading, writing, converting and manipulating images and metadata
Eclipse Public License 1.0
204 stars 58 forks source link

Create MS XMP metadata #78

Closed ivanooi closed 6 years ago

ivanooi commented 6 years ago

Hi,

Not sure why. I can't create the MS XMP. Custom XMP no problem.

This is the sample XMP generated by MS ( Right mouse click, properties -> Detail, Copyright field ) Thanks

<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.0-jc003">
  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description rdf:about=""
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
      xmpMM:InstanceID="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b">
      <dc:rights>
        <rdf:Alt>
          <rdf:li xml:lang="x-default">My Copyright</rdf:li>
        </rdf:Alt>
      </dc:rights>
    </rdf:Description>
  </rdf:RDF>
</x:xmpmeta>

<?xpacket end="w"?>

This is the code :
`

     ls_ns = "http://purl.org/dc/elements/1.1/";
     ( XMPMetaFactory.getSchemaRegistry()).registerNamespace( ls_ns, "dc" );

     if( meta.doesArrayItemExist( ls_ns, "rights", 1 )){
        meta.setArrayItem( ls_ns, "rights", 1, "My Copyright");
     }else{
        meta.deleteProperty( ls_ns, "rights");
        meta.setProperty ( ls_ns, "rights"   , "My Copyright");
     }

     ls_xmp = XMPMetaFactory.serializeToString( meta, new SerializeOptions().setPadding(10));
     System.out.println("ls_xmp=\r\n" + ls_xmp);
     metaList.add( new JpegXMP( ls_xmp ));

     FileInputStream  fin = new FileInputStream(  "A.JPG");
     FileOutputStream fout= new FileOutputStream( "B.JPG");

     Metadata.insertMetadata(metaList, fin, fout );

`

dragon66 commented 6 years ago

Are you saying the code didn’t add the XMP to the image? How did you know it’s not there? Did you try to read the image meta data using icafe after?

ivanooi commented 6 years ago

yes, I did. the XMP XML not there. and I had tired right click -> Properties -> Detail. You can't the info in Copyright filed

dragon66 commented 6 years ago

When you did the console output, did you get the string you created? If so, how did it loo like?

ivanooi commented 6 years ago

No... that the problem :-(

ivanooi commented 6 years ago

but there's no problem inserting custom XMP XML.

dragon66 commented 6 years ago

I am confused! What is MS XMP in your case and what do mean by Custom XMP?

ivanooi commented 6 years ago

This is what generated by MS Windows when you keyin info thru Properties -> Detail I would like to generate XMP like what MS Windows generated.

`<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>

My Copyright ` Custom mean, I create my own. eg : ` ` Thanks
dragon66 commented 6 years ago

Now I see. So you create custom XMP manually and used Adobe API to try to create something similar to what MS did but could’t create the XMP properly?

ivanooi commented 6 years ago

yes yes yes! :-D

ivanooi commented 6 years ago

Actually I'm using icafe. This is the code :

` ls_ns = "http://purl.org/dc/elements/1.1/"; ( XMPMetaFactory.getSchemaRegistry()).registerNamespace( ls_ns, "dc" );

 if( meta.doesArrayItemExist( ls_ns, "rights", 1 )){
    meta.setArrayItem( ls_ns, "rights", 1, "My Copyright");
 }else{
    meta.deleteProperty( ls_ns, "rights");
    meta.setProperty ( ls_ns, "rights"   , "My Copyright");
 }

 ls_xmp = XMPMetaFactory.serializeToString( meta, new SerializeOptions().setPadding(10));
 System.out.println("ls_xmp=\r\n" + ls_xmp);
 metaList.add( new JpegXMP( ls_xmp ));

 FileInputStream  fin = new FileInputStream(  "A.JPG");
 FileOutputStream fout= new FileOutputStream( "B.JPG");

 Metadata.insertMetadata(metaList, fin, fout );`
dragon66 commented 6 years ago

I tried your code and I got the following output. I think the issue is you set the dc:rights as an attribute not an element. I don't know how to add that as an element yet (using appendArrayItem() or something?)

ls_xmp=<?xpacket begin="?" id="W5M0MpCehiHzreSzNTczkc9d"?>

ivanooi commented 6 years ago

I see ...hmm....so , there is no way to add that using icafe, right?

dragon66 commented 6 years ago

ICAFE is not capable of creating XMP at the moment. But I believe icafe already added the XMP string created by Adobe API to the the image. You won't see it when you right click - > properties -> Detail as it will show the element value if it is there but in your case, you put it as an attribute.

ivanooi commented 6 years ago

anyway to store the data in element not?

ivanooi commented 6 years ago

If added at the correct place, I believe you will be able to see the data in Detail section... that the purpose :-P

dragon66 commented 6 years ago

Adobe XMP API should be able to do it but I never used it before.

You can actually try insert directly the XMP string you extracted from MS in your original question using icafe and you should see it afterwards. That way, you will prove it is the issue I mentioned which prevent it from showing.

ivanooi commented 6 years ago

direct modify the xml file. that's another way. I will try that. good idea

dragon66 commented 6 years ago

I am closing this thread as the issue is not directly related to icafe. I tried inserting the XMP string provided in your initial question and it works fine. As I mentioned earlier, icafe doesn't provide function to actually create XMP in the first place. It just inserts ready-made XMP in string or byte array format into different kinds of images.

ivanooi commented 6 years ago

Thanks. Finally I managed to use Adobe XMP to construct Microsoft XMP. Thanks again :-D

dragon66 commented 6 years ago

Great you made it!