List of usage examples for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_DATE_TIME_ORIGINAL
TagInfoAscii EXIF_TAG_DATE_TIME_ORIGINAL
To view the source code for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_DATE_TIME_ORIGINAL.
Click Source Link
From source file:it.inserpio.mapillary.gopro.importer.exif.EXIFPropertyReader.java
public static long getDateTimeOriginal(File imageFile) throws ImageReadException, IOException, ParseException { final IImageMetadata metadata = Imaging.getMetadata(imageFile); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; String dateTimeOriginal = jpegMetadata.getExif() .getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0]; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); return dateFormat.parse(dateTimeOriginal).getTime(); }
From source file:net.consulion.jeotag.PhotoLoader.java
private static Instant getTimeTaken(final TiffImageMetadata exif, final File file) { Instant instant = null;//ww w. j av a 2 s. co m if (exif != null) { try { final String[] dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); if (dateTimeOriginal.length == 1 && dateTimeOriginal[0].matches("\\d{4}\\:\\d{2}:\\d{2}\\s\\d{2}:\\d{2}:\\d{2}")) { final String[] split = dateTimeOriginal[0].split("\\s"); final String dateString = split[0]; final String timeString = split[1]; final String[] dateSplit = dateString.split("\\:"); final int year = Integer.parseInt(dateSplit[0]); final int month = Integer.parseInt(dateSplit[1]); final int day = Integer.parseInt(dateSplit[2]); final String[] timeSplit = timeString.split("\\:"); final int hour = Integer.parseInt(timeSplit[0]); final int minute = Integer.parseInt(timeSplit[1]); final int second = Integer.parseInt(timeSplit[2]); final LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, minute, second); instant = ldt.toInstant(ZoneOffset.ofHoursMinutes(0, 0)); } else { log(Level.WARNING, String.format("unknown date format in file %s", file.getPath())); } } catch (ImageReadException ex) { Logger.getLogger(PhotoLoader.class.getName()).log(Level.SEVERE, null, ex); } } return instant; }
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. ////ww 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: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. //// w w w. ja v a 2s . co m // 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: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 www .ja v a 2 s . c o 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 ww w. j av a 2s . co 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:joachimeichborn.geotag.io.jpeg.PictureMetadataReader.java
/** * Extract the time that is stored in the EXIF tag * {@link ExifTagConstants#EXIF_TAG_DATE_TIME_ORIGINAL} *//*w w w .j ava 2 s . co m*/ public String getTime() { if (!fetchedTime) { fetchedTime = true; time = getTagStringValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); } return time; }
From source file:de.aikiit.fotorenamer.image.MetaDataExtractor.java
/** * Helper to extract the date this image was created to be used during the * renaming process.//from ww w .ja va2s .co m * <br> * In the EXIF standard itself the following convention for dates as is * defined: <i> D. Other Tags DateTime The date and time of image creation. * In this standard it is the date and time the file was changed. The format * is "YYYY:MM:DD HH:MM:SS" with time shown in 24-hour format, and the date * and time separated by one blank character [20.H]. When the date and time * are unknown, all the character spaces except colons (":") may be filled * with blank characters, or else the Interoperability field may be filled * with blank characters. The character string length is 20 bytes including * NULL for termination. When the field is left blank, it is treated as * unknown. Tag = 306 (132.H) Type = ASCII Count = 20 Default = none </i> * <p> * If the extracted date value is empty - no new file name is generated. * * @param image Image to extract metadata from. * @return the date this image was created if found, format is * @throws ImageReadException If image cannot be read. * @throws IOException If an error occurs when accessing the image's * metadata. * @see <a href="http://www.exif.org/samples/canon-ixus.html">Canon EXIF * example page</a> * @see <a href="http://www.exif.org/specifications.html">EXIF * specifications</a> * @see <a href="http://www.exif.org/Exif2-2.PDF">EXIF2-2.pdf * specification</a> */ public static String generateCreationDateInCorrectFormat(final File image) throws ImageReadException, IOException { String dateValue = getExifMetadata(image, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); LOG.info("EXIF date value is: " + dateValue); // Invalid length of EXIF metadata, not complying to the standard. if (Strings.isNullOrEmpty(dateValue) || dateValue.length() != VALID_EXIF_DATE_LENGTH) { LOG.info("No valid creation date extracted from file " + image); return EMPTY_STRING; } // Date parsing with apache.DateUtils or JDK-DateFormats // does not work due to '-signs in the date string // (unparseable pattern is "'yyyy:MM:dd HH:mm:ss'") // replace special characters to extract digits only dateValue = dateValue.replaceAll(APOSTROPHE, EMPTY_STRING); dateValue = dateValue.replaceAll(COLON, EMPTY_STRING); dateValue = dateValue.replaceAll(SPACE, UNDERSCORE); dateValue += UNDERSCORE; //convert '2011:01:30 13:11:02' to "yyyyMMdd_HHmm_"+fileName dateValue += image.getName(); LOG.info("Target filename is: " + dateValue); return dateValue; }
From source file:at.ac.tuwien.qse.sepm.dao.repo.impl.JpegSerializer.java
@Override public void update(InputStream is, OutputStream os, PhotoMetadata metadata) throws DAOException { if (is == null) throw new IllegalArgumentException(); if (os == null) throw new IllegalArgumentException(); if (metadata == null) throw new IllegalArgumentException(); LOGGER.debug("updating photo metadata {}", metadata); String tags = "travelimg"; for (Tag element : metadata.getTags()) { tags += "/" + element.getName(); }// w ww . j av a 2s . c o m Rating rating = metadata.getRating(); tags += "/rating|" + rating; Place place = metadata.getPlace(); if (place != null) { tags += "/place|" + place.getCity() + "|" + place.getCountry() + "|" + place.getLatitude() + "|" + place.getLongitude(); } Journey journey = metadata.getJourney(); if (journey != null) { tags += "/journey|" + journey.getName() + "|" + journey.getStartDate().format(DATE_FORMATTER) + "|" + journey.getEndDate().format(DATE_FORMATTER); } Photographer photographer = metadata.getPhotographer(); if (photographer != null) { tags += "/photographer|" + photographer.getName(); } try { is.mark(Integer.MAX_VALUE); ImageMetadata imageData = Imaging.getMetadata(is, null); if (imageData == null) { LOGGER.debug("could not find image metadata"); throw new DAOException("No metadata found."); } if (!(imageData instanceof JpegImageMetadata)) { LOGGER.debug("metadata is of unknown type"); throw new DAOException("Metadata is of unknown type."); } JpegImageMetadata jpegData = (JpegImageMetadata) imageData; TiffOutputSet outputSet = new TiffOutputSet(); TiffImageMetadata exifData = jpegData.getExif(); if (exifData != null) { outputSet = exifData.getOutputSet(); } TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory(); outputSet.setGPSInDegrees(metadata.getLongitude(), metadata.getLatitude()); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, DATE_FORMATTER.format(metadata.getDatetime())); exifDirectory.removeField(ExifTagConstants.EXIF_TAG_USER_COMMENT); exifDirectory.add(ExifTagConstants.EXIF_TAG_USER_COMMENT, tags); is.reset(); new ExifRewriter().updateExifMetadataLossless(is, os, outputSet); } catch (IOException | ImageReadException | ImageWriteException ex) { LOGGER.warn("failed updating metadata"); throw new DAOException(ex); } LOGGER.debug("updated photo metadata"); }
From source file:at.ac.tuwien.qse.sepm.dao.repo.impl.JpegSerializer.java
private void readDate(JpegImageMetadata input, PhotoMetadata output) { LOGGER.debug("reading date from metadata"); TiffField field = input.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); if (field == null) { LOGGER.debug("metadata contains no date"); return;//from www .j a v a 2 s .c o m } String dateString = field.getValueDescription(); dateString = dateString.substring(1, dateString.length() - 1); // remove enclosing single quotes output.setDatetime(DATE_FORMATTER.parse(dateString, LocalDateTime::from)); LOGGER.debug("read date as {}", output.getDatetime()); }