List of usage examples for org.apache.commons.imaging.formats.tiff TiffImageMetadata getFieldValue
public String getFieldValue(final TagInfoXpString tag) throws ImageReadException
From source file:net.consulion.jeotag.PhotoLoader.java
private static Instant getTimeTaken(final TiffImageMetadata exif, final File file) { Instant instant = null;//from w ww. j av a 2 s . c o 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:adams.flow.transformer.exiftagoperation.ApacheCommonsExifTagExists.java
/** * Processes the incoming data.//w w w. j av a 2 s . c o m * * @param input the input to process * @param errors for storing errors * @return the generated output */ @Override protected Boolean doProcess(Object input, MessageCollection errors) { Boolean result; File inputFile; JpegImageMetadata meta; TiffImageMetadata exif; result = false; if (input instanceof String) inputFile = new PlaceholderFile((String) input).getAbsoluteFile(); else inputFile = ((File) input).getAbsoluteFile(); try { meta = (JpegImageMetadata) Imaging.getMetadata(inputFile); if (meta != null) { exif = meta.getExif(); if (exif != null) { result = (exif.getFieldValue(m_Tag.getTagInfo()) != null); } else { errors.add("No EXIF meta-data available: " + input); } } else { errors.add("No meta-data available: " + input); } } catch (Exception e) { errors.add("Failed to read EXIF tag " + m_Tag + " from: " + input, e); } return result; }
From source file:adams.flow.transformer.exiftagoperation.ApacheCommonsExifTagRead.java
/** * Processes the incoming data./*from w w w. j a va2s .c o m*/ * * @param input the input to process * @param errors for storing errors * @return the generated output */ @Override protected Object doProcess(Object input, MessageCollection errors) { Object result; File inputFile; JpegImageMetadata meta; TiffImageMetadata exif; result = null; if (input instanceof String) inputFile = new PlaceholderFile((String) input).getAbsoluteFile(); else inputFile = ((File) input).getAbsoluteFile(); try { meta = (JpegImageMetadata) Imaging.getMetadata(inputFile); if (meta != null) { exif = meta.getExif(); if (exif != null) { result = exif.getFieldValue(m_Tag.getTagInfo()); } else { errors.add("No EXIF meta-data available: " + input); } } else { errors.add("No meta-data available: " + input); } } catch (Exception e) { errors.add("Failed to read EXIF tag " + m_Tag + " from: " + input, e); } return result; }