List of usage examples for org.apache.commons.imaging.formats.tiff TiffField getValue
public Object getValue() throws ImageReadException
From source file:lucee.runtime.img.Metadata.java
private static void set(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo, Struct info) throws ImageReadException { final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo); if (field != null) { if (!info.containsKey(tagInfo.name)) { Object val = val(field.getValue()); if (val != null) info.setEL(tagInfo.name, val); }/* ww w . j a v a 2s . c om*/ } }
From source file:com.cons.gps2exif.exif.ReadMetaData.java
private static void printTagValue(JpegImageMetadata jpegMetadata, TagInfo tagInfo) throws ImageReadException { try {//from ww w. ja va 2 s . c o m // --------------------------------- // KEY PART: Extract EXIF by TagInfo // if you use findEXIFValueWithExactMatch, // the method throws NullPointerException when the provided tag does not present in the // metadata // --------------------------------- TiffField field = jpegMetadata.findEXIFValue(tagInfo); if (field != null) { // get actual stored value in metadata Object value = field.getValue(); System.out.println(tagInfo.name + ": " + toString(value)); } } catch (NullPointerException e) { } }
From source file:com.mycompany.jpegrenamer.MetaDataReader.java
private static Date getDateTagValue(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo) throws ImageReadException { final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo); if (field == null) { return null; } else {//from ww w.ja v a 2 s . c om Date d = (Date) field.getValue(); return d; } }
From source file:MetadataExample.java
public static void metadataExample(final File file) throws ImageReadException, IOException { // get all metadata stored in EXIF format (ie. from JPEG or TIFF). IImageMetadata metadata = Imaging.getMetadata(file); // System.out.println(metadata); if (metadata instanceof JpegImageMetadata) { JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; // Jpeg EXIF metadata is stored in a TIFF-based directory structure // and is identified with TIFF tags. // Here we look for the "x resolution" tag, but // we could just as easily search for any other tag. ////from www . j a va2 s . c om // see the TiffConstants file for a list of TIFF tags. System.out.println("file: " + file.getPath()); // print out various interesting EXIF tags. { printTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE); printTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_ORIENTATION); } printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_ISO); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE); System.out.println(); // simple interface to GPS data final TiffImageMetadata exifMetadata = jpegMetadata.getExif(); if (null != exifMetadata) { final TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS(); if (null != gpsInfo) { final String gpsDescription = gpsInfo.toString(); final double longitude = gpsInfo.getLongitudeAsDegreesEast(); final double latitude = gpsInfo.getLatitudeAsDegreesNorth(); System.out.println(" " + "GPS Description: " + gpsDescription); System.out.println(" " + "GPS Longitude (Degrees East): " + longitude); System.out.println(" " + "GPS Latitude (Degrees North): " + latitude); } } // more specific example of how to manually access GPS values final TiffField gpsLatitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); final TiffField gpsLatitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); final TiffField gpsLongitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); final TiffField gpsLongitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); if (gpsLatitudeRefField != null && gpsLatitudeField != null && gpsLongitudeRefField != null && gpsLongitudeField != null) { // all of these values are strings. final String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue(); final RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField.getValue()); final String gpsLongitudeRef = (String) gpsLongitudeRefField.getValue(); final RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField.getValue(); final RationalNumber gpsLatitudeDegrees = gpsLatitude[0]; final RationalNumber gpsLatitudeMinutes = gpsLatitude[1]; final RationalNumber gpsLatitudeSeconds = gpsLatitude[2]; final RationalNumber gpsLongitudeDegrees = gpsLongitude[0]; final RationalNumber gpsLongitudeMinutes = gpsLongitude[1]; final RationalNumber gpsLongitudeSeconds = gpsLongitude[2]; // This will format the gps info like so: // // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E System.out.println(" " + "GPS Latitude: " + gpsLatitudeDegrees.toDisplayString() + " degrees, " + gpsLatitudeMinutes.toDisplayString() + " minutes, " + gpsLatitudeSeconds.toDisplayString() + " seconds " + gpsLatitudeRef); System.out.println(" " + "GPS Longitude: " + gpsLongitudeDegrees.toDisplayString() + " degrees, " + gpsLongitudeMinutes.toDisplayString() + " minutes, " + gpsLongitudeSeconds.toDisplayString() + " seconds " + gpsLongitudeRef); } System.out.println(); final List<IImageMetadataItem> items = jpegMetadata.getItems(); for (int i = 0; i < items.size(); i++) { final TiffImageMetadata.Item item = (Item) items.get(i); System.out.println(" " + "item: " + item + "::" + item.getClass()); } System.out.println(); } }
From source file:de.tehame.examples.MetadataExample.java
public static void metadataExample(final File file) throws ImageReadException, IOException { // get all metadata stored in EXIF format (ie. from JPEG or TIFF). final ImageMetadata metadata = Imaging.getMetadata(file); System.out.println(metadata); if (metadata instanceof JpegImageMetadata) { final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; // Jpeg EXIF metadata is stored in a TIFF-based directory structure // and is identified with TIFF tags. // Here we look for the "x resolution" tag, but // we could just as easily search for any other tag. ////from w w w .j a v a 2s . c om // see the TiffConstants file for a list of TIFF tags. System.out.println("file: " + file.getPath()); // print out various interesting EXIF tags. printTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_XRESOLUTION); printTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_ISO); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE); System.out.println(); // simple interface to GPS data final TiffImageMetadata exifMetadata = jpegMetadata.getExif(); if (null != exifMetadata) { final TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS(); if (null != gpsInfo) { final String gpsDescription = gpsInfo.toString(); final double longitude = gpsInfo.getLongitudeAsDegreesEast(); final double latitude = gpsInfo.getLatitudeAsDegreesNorth(); System.out.println(" " + "GPS Description: " + gpsDescription); System.out.println(" " + "GPS Longitude (Degrees East): " + longitude); System.out.println(" " + "GPS Latitude (Degrees North): " + latitude); } } // more specific example of how to manually access GPS values final TiffField gpsLatitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); final TiffField gpsLatitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); final TiffField gpsLongitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); final TiffField gpsLongitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); if (gpsLatitudeRefField != null && gpsLatitudeField != null && gpsLongitudeRefField != null && gpsLongitudeField != null) { // all of these values are strings. final String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue(); final RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField.getValue()); final String gpsLongitudeRef = (String) gpsLongitudeRefField.getValue(); final RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField.getValue(); final RationalNumber gpsLatitudeDegrees = gpsLatitude[0]; final RationalNumber gpsLatitudeMinutes = gpsLatitude[1]; final RationalNumber gpsLatitudeSeconds = gpsLatitude[2]; final RationalNumber gpsLongitudeDegrees = gpsLongitude[0]; final RationalNumber gpsLongitudeMinutes = gpsLongitude[1]; final RationalNumber gpsLongitudeSeconds = gpsLongitude[2]; // This will format the gps info like so: // // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E System.out.println(" " + "GPS Latitude: " + gpsLatitudeDegrees.toDisplayString() + " degrees, " + gpsLatitudeMinutes.toDisplayString() + " minutes, " + gpsLatitudeSeconds.toDisplayString() + " seconds " + gpsLatitudeRef); System.out.println(" " + "GPS Longitude: " + gpsLongitudeDegrees.toDisplayString() + " degrees, " + gpsLongitudeMinutes.toDisplayString() + " minutes, " + gpsLongitudeSeconds.toDisplayString() + " seconds " + gpsLongitudeRef); } System.out.println(); final List<ImageMetadataItem> items = jpegMetadata.getItems(); for (int i = 0; i < items.size(); i++) { final ImageMetadataItem item = items.get(i); System.out.println(" " + "item: " + item); } System.out.println(); } }
From source file:lucee.runtime.img.Metadata.java
private static void gps(JpegImageMetadata jpegMetadata, Struct info) throws ImageReadException { Struct gps = new StructImpl(); info.setEL("gps", gps); info = gps;//from w w w . ja v a 2 s .c o m final TiffImageMetadata exifMetadata = jpegMetadata.getExif(); Double longitude = null; Double latitude = null; if (null != exifMetadata) { final TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS(); if (null != gpsInfo) { //final String gpsDescription = gpsInfo.toString(); longitude = gpsInfo.getLongitudeAsDegreesEast(); latitude = gpsInfo.getLatitudeAsDegreesNorth(); } } // more specific example of how to manually access GPS values final TiffField gpsLatitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); final TiffField gpsLatitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); final TiffField gpsLongitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); final TiffField gpsLongitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); if (gpsLatitudeRefField != null && gpsLatitudeField != null && gpsLongitudeRefField != null && gpsLongitudeField != null) { // all of these values are strings. final String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue(); final RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField.getValue()); final String gpsLongitudeRef = (String) gpsLongitudeRefField.getValue(); final RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField.getValue(); info.setEL("GPS Latitude", gpsLatitude[0].toDisplayString() + "\"" + gpsLatitude[1].toDisplayString() + "'" + gpsLatitude[2].toDisplayString()); info.setEL("GPS Latitude Ref", gpsLatitudeRef); Struct sct = new StructImpl(); gps.setEL("latitude", sct); sct.setEL("degrees", gpsLatitude[0].doubleValue()); sct.setEL("minutes", gpsLatitude[1].doubleValue()); sct.setEL("seconds", gpsLatitude[2].doubleValue()); sct.setEL("ref", gpsLatitudeRef); sct.setEL("decimal", latitude); info.setEL("GPS Longitude", gpsLongitude[0].toDisplayString() + "\"" + gpsLongitude[1].toDisplayString() + "'" + gpsLongitude[2].toDisplayString()); info.setEL("GPS Longitude Ref", gpsLongitudeRef); sct = new StructImpl(); gps.setEL("longitude", sct); sct.setEL("degrees", gpsLongitude[0].doubleValue()); sct.setEL("minutes", gpsLongitude[1].doubleValue()); sct.setEL("seconds", gpsLongitude[2].doubleValue()); sct.setEL("ref", gpsLongitudeRef); sct.setEL("decimal", longitude); } }
From source file:name.hampton.mike.gallery.MetadataExtractor.java
public Map<String, Object> extractImageMetaData(final InputStream inputStream, Map<String, Object> metadataH) throws ImageReadException, IOException { // get all metadata stored in EXIF format (ie. from JPEG or TIFF). final ImageMetadata metadata = Imaging.getMetadata(inputStream, null); if (metadata instanceof JpegImageMetadata) { final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; // Jpeg EXIF metadata is stored in a TIFF-based directory structure // and is identified with TIFF tags. // Here we look for the "x resolution" tag, but // we could just as easily search for any other tag. ////from ww w . j av a 2 s .co m // see the TiffConstants file for a list of TIFF tags. // out.println("file: " + file.getPath()); JpegPhotoshopMetadata photoshopmetadata = jpegMetadata.getPhotoshop(); metadataH.put("photoshop", photoshopmetadata); BufferedImage thumbnail = jpegMetadata.getEXIFThumbnail(); metadataH.put("hasEXIFThumbnail", null != thumbnail); Map<String, Object> jpegMetadataH = new HashMap<String, Object>(); metadataH.put("jpegMetadata", jpegMetadataH); // print out various interesting EXIF tags. recordTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_XRESOLUTION, jpegMetadataH); recordTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME, jpegMetadataH); recordTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, jpegMetadataH); recordTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED, jpegMetadataH); recordTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_ISO, jpegMetadataH); recordTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE, jpegMetadataH); recordTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE, jpegMetadataH); recordTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE, jpegMetadataH); recordTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF, jpegMetadataH); recordTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, jpegMetadataH); recordTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF, jpegMetadataH); recordTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, jpegMetadataH); // simple interface to GPS data final TiffImageMetadata exifMetadata = jpegMetadata.getExif(); if (null != exifMetadata) { final TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS(); if (null != gpsInfo) { final String gpsDescription = gpsInfo.toString(); final double longitude = gpsInfo.getLongitudeAsDegreesEast(); final double latitude = gpsInfo.getLatitudeAsDegreesNorth(); jpegMetadataH.put("GPSDescription", gpsDescription); jpegMetadataH.put("GPSLongitude", longitude); jpegMetadataH.put("GPSLatitude", latitude); } List<TiffField> allFields = exifMetadata.getAllFields(); List<Map<String, Object>> allFieldsL = new ArrayList<Map<String, Object>>(); jpegMetadataH.put("allFields", allFieldsL); if (null != allFields) { for (TiffField field : allFields) { Map<String, Object> fieldH = new HashMap<String, Object>(); allFieldsL.add(fieldH); fieldH.put("fieldType", field.getFieldTypeName()); if (field.getFieldType().equals(FieldType.RATIONAL)) { // These fields format oddly, must be strings fieldH.put("value", field.getValue().toString()); } fieldH.put("descriptionWithoutValue", field.getDescriptionWithoutValue()); fieldH.put("directoryType", field.getDirectoryType()); fieldH.put("tagName", field.getTagName()); fieldH.put("valueDescription", field.getValueDescription()); } } } // more specific example of how to manually access GPS values final TiffField gpsLatitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); final TiffField gpsLatitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); final TiffField gpsLongitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); final TiffField gpsLongitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); if (gpsLatitudeRefField != null && gpsLatitudeField != null && gpsLongitudeRefField != null && gpsLongitudeField != null) { // all of these values are strings. final String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue(); final RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField.getValue()); final String gpsLongitudeRef = (String) gpsLongitudeRefField.getValue(); final RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField.getValue(); final RationalNumber gpsLatitudeDegrees = gpsLatitude[0]; final RationalNumber gpsLatitudeMinutes = gpsLatitude[1]; final RationalNumber gpsLatitudeSeconds = gpsLatitude[2]; final RationalNumber gpsLongitudeDegrees = gpsLongitude[0]; final RationalNumber gpsLongitudeMinutes = gpsLongitude[1]; final RationalNumber gpsLongitudeSeconds = gpsLongitude[2]; // This will format the gps info like so: // // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E Map<String, Object> gpsH = new HashMap<String, Object>(); jpegMetadataH.put("gps", gpsH); Map<String, Object> gpsLatitudeH = new HashMap<String, Object>(); Map<String, Object> gpsLongitudeH = new HashMap<String, Object>(); gpsH.put("latitude", gpsLatitudeH); gpsH.put("longitude", gpsLongitudeH); gpsLatitudeH.put("degrees", gpsLatitudeDegrees.toDisplayString()); gpsLatitudeH.put("minutes", gpsLatitudeMinutes.toDisplayString()); gpsLatitudeH.put("seconds", gpsLatitudeSeconds.toDisplayString()); gpsLatitudeH.put("display", gpsLatitudeRef); gpsLongitudeH.put("degrees", gpsLongitudeDegrees.toDisplayString()); gpsLongitudeH.put("minutes", gpsLongitudeMinutes.toDisplayString()); gpsLongitudeH.put("seconds", gpsLongitudeSeconds.toDisplayString()); gpsLongitudeH.put("display", gpsLongitudeRef); } } return metadataH; }
From source file:com.cons.gps2exif.exif.ReadMetaData.java
public void showAllMetaData(final File file) throws ImageReadException, IOException { // get all metadata stored in EXIF format (ie. from JPEG or TIFF). final ImageMetadata metadata = Imaging.getMetadata(file); if (metadata instanceof JpegImageMetadata) { final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; // Jpeg EXIF metadata is stored in a TIFF-based directory structure // and is identified with TIFF tags. // Here we look for the "x resolution" tag, but // we could just as easily search for any other tag. ////from w ww . j a va 2s . c o m // see the TiffConstants file for a list of TIFF tags. System.out.println("file: " + file.getPath()); // print out various interesting EXIF tags. showTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_XRESOLUTION); showTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME); showTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); showTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED); showTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_ISO); showTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE); showTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE); showTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE); showTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); showTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE); showTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); showTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE); showTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF); showTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE); System.out.println(); // simple interface to GPS data final TiffImageMetadata exifMetadata = jpegMetadata.getExif(); if (null != exifMetadata) { final TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS(); if (null != gpsInfo) { final String gpsDescription = gpsInfo.toString(); final double longitude = gpsInfo.getLongitudeAsDegreesEast(); final double latitude = gpsInfo.getLatitudeAsDegreesNorth(); System.out.println(" " + "GPS Description: " + gpsDescription); System.out.println(" " + "GPS Longitude (Degrees East): " + longitude); System.out.println(" " + "GPS Latitude (Degrees North): " + latitude); } } // more specific example of how to manually access GPS values final TiffField gpsLatitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); final TiffField gpsLatitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); final TiffField gpsLongitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); final TiffField gpsLongitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); if (gpsLatitudeRefField != null && gpsLatitudeField != null && gpsLongitudeRefField != null && gpsLongitudeField != null) { // all of these values are strings. final String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue(); final RationalNumber gpsLatitude[] = (RationalNumber[]) (gpsLatitudeField.getValue()); final String gpsLongitudeRef = (String) gpsLongitudeRefField.getValue(); final RationalNumber gpsLongitude[] = (RationalNumber[]) gpsLongitudeField.getValue(); final RationalNumber gpsLatitudeDegrees = gpsLatitude[0]; final RationalNumber gpsLatitudeMinutes = gpsLatitude[1]; final RationalNumber gpsLatitudeSeconds = gpsLatitude[2]; final RationalNumber gpsLongitudeDegrees = gpsLongitude[0]; final RationalNumber gpsLongitudeMinutes = gpsLongitude[1]; final RationalNumber gpsLongitudeSeconds = gpsLongitude[2]; // This will format the gps info like so: // // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E System.out.println(" " + "GPS Latitude: " + gpsLatitudeDegrees.toDisplayString() + " degrees, " + gpsLatitudeMinutes.toDisplayString() + " minutes, " + gpsLatitudeSeconds.toDisplayString() + " seconds " + gpsLatitudeRef); System.out.println(" " + "GPS Longitude: " + gpsLongitudeDegrees.toDisplayString() + " degrees, " + gpsLongitudeMinutes.toDisplayString() + " minutes, " + gpsLongitudeSeconds.toDisplayString() + " seconds " + gpsLongitudeRef); } System.out.println(); final List<ImageMetadataItem> items = jpegMetadata.getItems(); for (int i = 0; i < items.size(); i++) { final ImageMetadataItem item = items.get(i); System.out.println(" " + "item: " + item); } System.out.println(); } }
From source file:com.mycompany.jpegrenamer.MetaDataReader.java
public Map<String, String> getExifMetadata(final File jpegImageFile) throws ImageReadException, IOException, ImageWriteException { Map<String, String> res = new HashMap<>(); Map<String, String> location = new HashMap(); ;/*from ww w . j a v a2 s . c o m*/ // note that metadata might be null if no metadata is found. final ImageMetadata metadata = Imaging.getMetadata(jpegImageFile); boolean isClassOk = metadata instanceof JpegImageMetadata; if (!isClassOk || (null == metadata)) { return res; } final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (jpegMetadata == null) { logger.info("File does not contain metadata - " + jpegImageFile.getCanonicalPath()); return res; } String dateOfCaptureString = getTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME); SimpleDateFormat sdf = new SimpleDateFormat("''yyyy:MM:dd hh:mm:ss''"); Date dateOfCapture = null; try { dateOfCapture = sdf.parse(dateOfCaptureString); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss", Locale.ENGLISH); res.put("date", df.format(dateOfCapture)); } catch (ParseException ex) { logger.error("", ex); } // s = getTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME); printTagValue(jpegMetadata, TiffTagConstants.TIFF_TAG_DATE_TIME); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); printTagValue(jpegMetadata, ExifTagConstants.EXIF_TAG_DATE_TIME_DIGITIZED); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); printTagValue(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE); if (null != jpegMetadata) { // note that exif might be null if no Exif metadata is found. final TiffImageMetadata exif = jpegMetadata.getExif(); //logger.info(jpegMetadata.toString()); if (null != exif) { //logger.info(exif.toString()); final TiffImageMetadata.GPSInfo gpsInfo = exif.getGPS(); if (null != gpsInfo) { final String gpsDescription = gpsInfo.toString(); final double longitude = gpsInfo.getLongitudeAsDegreesEast(); final double latitude = gpsInfo.getLatitudeAsDegreesNorth(); logger.info(" " + "GPS Description: " + gpsDescription); logger.info(" " + "GPS Longitude (Degrees East): " + longitude); logger.info(" " + "GPS Latitude (Degrees North): " + latitude); try { Locale fmtLocale = Locale.US; NumberFormat formatter = NumberFormat.getNumberInstance(fmtLocale); formatter.setGroupingUsed(false); location = getAddressByGpsCoordinates(formatter.format(latitude), formatter.format(longitude)); if (location != null) { res.putAll(location); } } catch (MalformedURLException ex) { logger.error("", ex); } catch (org.json.simple.parser.ParseException ex) { logger.error("", ex); } logger.info(" " + location); } // more specific example of how to manually access GPS values final TiffField gpsLatitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); final TiffField gpsLatitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE); final TiffField gpsLongitudeRefField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); final TiffField gpsLongitudeField = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE); if (gpsLatitudeRefField != null && gpsLatitudeField != null && gpsLongitudeRefField != null && gpsLongitudeField != null) { // all of these values are strings. final String gpsLatitudeRef = (String) gpsLatitudeRefField.getValue(); final RationalNumber[] gpsLatitude = (RationalNumber[]) (gpsLatitudeField.getValue()); final String gpsLongitudeRef = (String) gpsLongitudeRefField.getValue(); final RationalNumber[] gpsLongitude = (RationalNumber[]) gpsLongitudeField.getValue(); final RationalNumber gpsLatitudeDegrees = gpsLatitude[0]; final RationalNumber gpsLatitudeMinutes = gpsLatitude[1]; final RationalNumber gpsLatitudeSeconds = gpsLatitude[2]; final RationalNumber gpsLongitudeDegrees = gpsLongitude[0]; final RationalNumber gpsLongitudeMinutes = gpsLongitude[1]; final RationalNumber gpsLongitudeSeconds = gpsLongitude[2]; // This will format the gps info like so: // // gpsLatitude: 8 degrees, 40 minutes, 42.2 seconds S // gpsLongitude: 115 degrees, 26 minutes, 21.8 seconds E logger.info(" " + "GPS Latitude: " + gpsLatitudeDegrees.toDisplayString() + " degrees, " + gpsLatitudeMinutes.toDisplayString() + " minutes, " + gpsLatitudeSeconds.toDisplayString() + " seconds " + gpsLatitudeRef); logger.info(" " + "GPS Longitude: " + gpsLongitudeDegrees.toDisplayString() + " degrees, " + gpsLongitudeMinutes.toDisplayString() + " minutes, " + gpsLongitudeSeconds.toDisplayString() + " seconds " + gpsLongitudeRef); } logger.info(""); final List<ImageMetadata.ImageMetadataItem> items = jpegMetadata.getItems(); for (int i = 0; i < items.size(); i++) { final ImageMetadata.ImageMetadataItem item = items.get(i); // logger.info(" " + "item: " + item); } logger.info(""); } } return res; }
From source file:net.tourbook.photo.Photo.java
/** * GPS area info/*from ww w . j a v a 2 s . c o m*/ */ private String getExifValueGpsArea(final JpegImageMetadata jpegMetadata) { try { final TiffField field = jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_AREA_INFORMATION); if (field != null) { final Object fieldValue = field.getValue(); if (fieldValue != null) { /** * source: Exif 2.2 specification * * <pre> * * Table 6 Character Codes and their Designation * * Character Code Code Designation (8 Bytes) References * ASCII 41.H, 53.H, 43.H, 49.H, 49.H, 00.H, 00.H, 00.H ITU-T T.50 IA5 * JIS A.H, 49.H, 53.H, 00.H, 00.H, 00.H, 00.H, 00.H JIS X208-1990 * Unicode 55.H, 4E.H, 49.H, 43.H, 4F.H, 44.H, 45.H, 00.H Unicode Standard * Undefined 00.H, 00.H, 00.H, 00.H, 00.H, 00.H, 00.H, 00.H Undefined * * </pre> */ final byte[] byteArrayValue = field.getByteArrayValue(); final int fieldLength = byteArrayValue.length; if (fieldLength > 0) { /** * <pre> * * skipping 1 + 6 characters: * * 1 character code * 2...7 have no idea why these bytes are set to none valid characters * * </pre> */ final byte[] valueBytes = Arrays.copyOfRange(byteArrayValue, 7, fieldLength); String valueString = null; final byte firstByte = byteArrayValue[0]; if (firstByte == 0x55) { valueString = new String(valueBytes, UI.UTF_16); } else { valueString = new String(valueBytes); } return valueString; } } } } catch (final Exception e) { // ignore } return null; }