I am looking to extract the camera related information from a jpg using Java. I have looked around but have not been able to find a solution to my problem. I am exporting my photos from Aperture on my mac (OS X 10.7) and want to use the data from Aperture that is available in the file info.
Any ideas?
I am looking to have Dimensions and Key Words extracted from photos like this one: 80.167.88.49/masters/test.html. Currently i get an exception when trying to use the Metadata Extractor. I don't know if Aperture is adding information that cannot be handled but it throws an exception on all photos from Aperture.
Exception in thread "main" java.lang.NoClassDefFoundError: com/adobe/xmp/XMPException
at com.drew.imaging.jpeg.JpegMetadataReader.extractMetadataFromJpegSegmentReader(Unknown Source)
at com.drew.imaging.jpeg.JpegMetadataReader.readMetadata(Unknown Source)
at com.drew.imaging.ImageMetadataReader.readMetadata(Unknown Source)
at com.drew.imaging.ImageMetadataReader.readMetadata(Unknown Source)
at ImageScaler.main(ImageScaler.java:141)
Caused by: java.lang.ClassNotFoundException: com.adobe.xmp.XMPException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 5 more
Code:
public static void main (String[] args){
File image = new File("/Users/peterla/Desktop/P8214462.jpg");
Metadata metadata = null;
try {
metadata = ImageMetadataReader.readMetadata(image);
} catch (ImageProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Directory directory;
// Keywords
directory = metadata.getDirectory(IptcDirectory.class);
String keywords[] = directory.getStringArray(IptcDirectory.TAG_KEYWORDS);
// Dimensions
directory = metadata.getDirectory(JpegDirectory.class);
String height = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
String width = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
}
Metadata Extractor has a simple interface for reading several types of metadata from many digital image formats. This includes the EXIF metadata format used in jpeg images. The library has good Javadoc style documentation.
The primary entry point into the library is the ImageMetadataReader object.
The Getting Started page has a nice intro, including a nice example of how to get a value for a specific tag from EXIF format metadata.
Update: Example for Extracting Keywords and Dimensions
Directory directory;
// Keywords
directory = metadata.getDirectory(IptcDirectory.class);
String keywords[] = directory.getStringArray(IptcDirectory.TAG_KEYWORDS);
// Dimensions
directory = metadata.getDirectory(JpegDirectory.class);
String height = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
String width = directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
Alternatives
Alternatives include the builtin java ImageIO library and Sanselan.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With