|
Replies:
4
-
Last Post:
Sep 7, 2008 4:37 AM
by: pkgdk
|
|
|
|
|
|
|
How to retrieve XMP metadata from JPEG
Posted:
May 24, 2008 8:42 PM
|
|
|
I am new to this area. I attempting to extract the XMP metadata from a JPEG file. The spec states that "app1" will contain the XMP metadata. This is to retrieve the metadata regarding licensing from the JPEG. I have a test file the was created with Adobe Photoshop that has XMP metadata in the file. However, I cannot seem to find the metadata located in the JPEG itself. I have used the "getImageMetadata" method to extract the metadata and have examined the structure and not found where the xmp metadata is located. Any help would be appreciated.
|
|
|
|
|
|
|
Re: How to retrieve XMP metadata from JPEG
Posted:
May 25, 2008 11:47 AM
in response to: richwt
|
|
|
I am not sure but think XMP extraction is not supported by the metadata extraction. You may have to extract the data from app1 yourself.
|
|
|
|
|
|
|
|
Re: [JAI-IMAGEIO] Re: How to retrieve XMP metadata from JPEG
Posted:
May 25, 2008 11:47 AM
in response to: marcojacob
|
|
|
I think you can extract the XMP metadata as a string. I suggest you to use then JempBox (http://www.jempbox.org) to process it.
On May 25, 2008, at 20:47 , jai-imageio@javadesktop.org wrote:
> I am not sure but think XMP extraction is not supported by the > metadata extraction. You may have to extract the data from > app1 yourself. > [Message sent by forum member 'marcojacob' (marcojacob)] > > http://forums.java.net/jive/thread.jspa?messageID=276478 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net > For additional commands, e-mail: interest-help@jai- > imageio.dev.java.net > >
-- Fabrizio Giudici, Ph.D. - Java Architect, Project Manager Tidalwave s.a.s. - "We make Java work. Everywhere." weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/blog Fabrizio.Giudici@tidalwave.it - mobile: +39 348.150.6941
--------------------------------------------------------------------- To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
|
|
|
|
|
|
|
|
Re: [JAI-IMAGEIO] Re: How to retrieve XMP metadata from JPEG
Posted:
May 25, 2008 9:57 PM
in response to: Fabrizio Giudici
|
|
|
Thanks for putting me in the right direction. I have written the following code and does what I want now. It reads the XMP metadata from a standard JPEG file not a JPEG200 file (this is next on the list). I am now in the process of modifing the code to write back to the file updated XMP metadata. Thanks to all who helped.
package org.raven7.service.jpeg;
import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException;
import org.w3c.dom.Document;
public class XMPJPEGReader { private static final int xmpJPEGStart = 0xFF; private static final int xmpJPEGStop = 0xE1;
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub File inputFile = new File("c:/data/output/images.jpg"); String xmp = getJPEGXMP(inputFile); System.out.println(xmp); Document docName = org.raven7.W3CUtilities.W3CUtilities .covertStringToW3CDocument(xmp); org.raven7.W3CUtilities.W3CUtilities.convertW3CDocumentXML(docName); String licenseParts = org.raven7.XMPUtilities.XMPUtilities .getLicenseParts(docName, true, "JPEG"); System.out.println(licenseParts);
}
/** * Method readJPEGFile * * Reads a standard JPEG file and returns the XMP Metadata as a string to the calling application * * @param inputFile * @return java.lang.String */ public static String readJPEGFile(File inputFile) { String result = getJPEGXMP(inputFile); return result; }
/** * Method checkXAPNamespace * * Checks that the XMP namespace has been found in the inputStream * * @param inputStream * @return java.lang.String */ private static String checkXAPNamespace(FileInputStream inputStream) { String result = null; String resultingString = convertJPEGSegmentToString(inputStream); if (resultingString .startsWith(org.raven7.constants.NameSpaceConstants.XMPNAMESPACE)) { result = resultingString.substring(29); } return result; }
/** * Method getJPEGXMP * * Given an input file the XMP metadata in the XMP File is read and the XMP metadata is returned as a String * * @param inputFile * @return java.lang.String */ private static String getJPEGXMP(File inputFile) { FileInputStream inputStream = null; try { // Open the JPEG file and read the file into a stream inputStream = new FileInputStream(inputFile); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int offSet = 0; String result = null; try { // Check for end of the file while ((offSet = inputStream.read()) != -1) if (offSet == xmpJPEGStart && inputStream.read() == xmpJPEGStop) { result = checkXAPNamespace(inputStream); if (result != null) break; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; }
/** * Method convertJPEGSegmentToString * * Converts the inputStream to a String * * @param inputStream * @return java.lang.String */ private static String convertJPEGSegmentToString(FileInputStream inputStream) { String result = null; // Convert the inputStream to a data stream DataInputStream dataStream = new DataInputStream(inputStream); byte[] buffer = null; try { // convert the data stream to bytes buffer = new byte[dataStream.readShort() - 2]; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { dataStream.read(buffer); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } result = new String(buffer); // Return the buffer as a string return result; }
/** * Method convertJPEGSegmentToBytes * * Converts the Input stream to a Byte array * * @param inputStream * @return java.lang.Byte */ private static byte[] convertJPEGSegmentToBytes(FileInputStream inputStream) { byte[] result = null; // Convert the inputStream to a data stream DataInputStream dataStream = new DataInputStream(inputStream); try { // convert the data stream to bytes result = new byte[dataStream.readShort() - 2]; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Return the buffer as a bytes return result; }
}
|
|
|
|
|
|
|
|
Re: [JAI-IMAGEIO] Re: How to retrieve XMP metadata from JPEG
Posted:
Sep 7, 2008 4:37 AM
in response to: richwt
|
|
|
I was inspired by your sample code and used it as a basis for XMP extraction in my Java based gallery. I rewrote and optimized it for production use (and fixed what seems like a minor bug in how you read the JPEG APP1 segment size) and it works like a charm. You can have a look at it here:
http://www.pkg.dk/tips/How-to-extract-XMP-metadata-from-JPEG-files-in-Java/
You can use and modify it for your own purpose if you like it. A sample command line program is included in the class, so you can easily test it with your own JPEGs.
|
|
|
|
|