Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting EXIF XPKEYWORDS with Sanselan
    primarykey
    data
    text
    <p>I've been researching ways to write tags to my images similar to how Windows Live Photo Gallery works. I've played with several different libraries (metadata-extractor,jhead,jheader,sanselan) but have only really found Sanselan to accomodate writing the data back in that I need.</p> <p>I followed Apache's <a href="http://commons.apache.org/proper/commons-imaging//xref-test/org/apache/sanselan/sampleUsage/WriteExifMetadataExample.html" rel="nofollow">WriteExifMetadataExample</a> to a T &amp; It worked flawlessly for updating the GPS data and Aperture.</p> <p>I then attempted to modify the example to update <code>EXIF_TAG_XPKEYWORDS</code> rather than <code>EXIF_TAG_APERTURE_VALUE</code>.</p> <p>In the above-linked example, I replaced the <code>TiffOutputField.create</code> line with the following:</p> <pre><code>String currentTagsAsString = new String((byte[]) jpegMetadata.findEXIFValue(ExifTagConstants.EXIF_TAG_XPKEYWORDS).getValue()); System.out.println("current tags: '" + currentTagsAsString + "'"); String newTag = "h e l l o"; String newTagsAsString = currentTagsAsString.trim() + " ; " + newTag + " "; System.out.println("new desired tags: '" + newTagsAsString + "'"); TiffOutputField keywords = new TiffOutputField(ExifTagConstants.EXIF_TAG_XPKEYWORDS, FieldType.FIELD_TYPE_BYTE, newTagsAsString.length(), newTagsAsString.getBytes()); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_XPKEYWORDS); exifDirectory.add(keywords); </code></pre> <p>Other than commenting out the aperature and GPS update code, the rest I left alone. I will admit the format of the byte array has me a little confused so that may very well be the issue.</p> <p>I get no warnings/errors/etc. The process completes normally but the new Image file does not contain the updated tags. Why does the new image not contain the updated tags? Is there an easier/better way?</p> <p><em>UPDATE: I have edited the code to work with the 1.0 RC commons-imaging API instead, however the results are the same. I am including the code I used here for completeness</em></p> <pre><code>TiffImageMetadata metadata = toTiffMetadata(Imaging.getMetadata(inputFile)); System.out.println(metadata.getFieldValue(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS)); TiffOutputSet outputSet = metadata.getOutputSet(); TiffOutputDirectory exif = outputSet.getOrCreateExifDirectory(); exif.removeField(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS); exif.add(MicrosoftTagConstants.EXIF_TAG_XPKEYWORDS, "helloworld;goodbye;"); writeFileWithNewTag(inputFile,destinationFile,outputSet); </code></pre> <p><em>The new code works great if i use something like <code>EXIF_TAG_XPAUTHOR</code>, but using <code>EXIF_TAG_XPKEYWORDS</code> produces no errors or warnings or messages of any kind and the new file simply doens't contain the new tag data</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload