List of usage examples for org.apache.commons.imaging.formats.jpeg JpegImageMetadata getExif
public TiffImageMetadata getExif()
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 TiffImageMetadata getExif(final File file) { TiffImageMetadata exif = null;/*from w ww . j a v a 2 s. co m*/ try { final IImageMetadata metadata = Imaging.getMetadata(file); if (metadata != null) { final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; exif = jpegMetadata.getExif(); } else { log(Level.WARNING, String.format("No metadata found for file %s", file)); } } catch (final ImageReadException | IOException ex) { Logger.getLogger(PhotoLoader.class.getName()).log(Level.SEVERE, null, ex); } return exif; }
From source file:it.inserpio.mapillary.gopro.importer.exif.EXIFPropertyWriter.java
public static void setExifGPSTag(File jpegImageFile, File jpegImageOutputFile, Coordinates coordinates) throws IOException, ImageReadException, ImageWriteException { OutputStream os = null;// ww w. j av a2 s . co m boolean canThrow = false; try { TiffOutputSet outputSet = null; final IImageMetadata metadata = Imaging.getMetadata(jpegImageFile); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (jpegMetadata != null) { final TiffImageMetadata exif = jpegMetadata.getExif(); if (exif != null) { outputSet = exif.getOutputSet(); } } if (outputSet == null) { outputSet = new TiffOutputSet(); } outputSet.setGPSInDegrees(coordinates.getLongitude(), coordinates.getLatitude()); outputSet.getGPSDirectory().removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF); outputSet.getGPSDirectory().add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF, GpsTagConstants.GPS_TAG_GPS_DEST_BEARING_REF_VALUE_TRUE_NORTH); outputSet.getGPSDirectory().removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); outputSet.getGPSDirectory().add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, new RationalNumber[] { RationalNumber.valueOf(coordinates.getDirection()) }); //outputSet.getRootDirectory().removeField(305); os = new FileOutputStream(jpegImageOutputFile); os = new BufferedOutputStream(os); new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet); canThrow = true; } finally { IoUtils.closeQuietly(canThrow, os); } }
From source file:lucee.runtime.img.Metadata.java
private static void fillExif(String format, InputStream is, Struct info) throws ImageReadException, IOException { // get all metadata stored in EXIF format (ie. from JPEG or TIFF). IImageMetadata metadata = Imaging.getMetadata(is, "test." + format); if (metadata == null) return;// w ww . ja v a 2 s .c o m if (metadata instanceof JpegImageMetadata) { final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; // EXIF if (jpegMetadata != null) { try { set(jpegMetadata.getExif().getItems(), info, null); } catch (Throwable t) { ExceptionUtil.rethrowIfNecessary(t); } } // GPS try { gps(jpegMetadata, info); } catch (Throwable t) { ExceptionUtil.rethrowIfNecessary(t); } } }
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;/*ww w . j av a2 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:net.mozq.picto.core.ProcessCore.java
private static GPSInfo getEXIFGpsInfo(ImageMetadata imageMetadata) { if (imageMetadata == null) { return null; }/*w ww. j a v a 2 s . c o m*/ TiffImageMetadata tiffImageMetadata = null; if (imageMetadata instanceof JpegImageMetadata) { JpegImageMetadata jpegMetadata = (JpegImageMetadata) imageMetadata; tiffImageMetadata = jpegMetadata.getExif(); } else if (imageMetadata instanceof TiffImageMetadata) { tiffImageMetadata = (TiffImageMetadata) imageMetadata; } if (tiffImageMetadata == null) { return null; } GPSInfo gpsInfo; try { gpsInfo = tiffImageMetadata.getGPS(); } catch (ImageReadException e) { return null; } return gpsInfo; }
From source file:com.att.aro.core.bestpractice.impl.ImageMetaDataImpl.java
private void extractMetadata(String fullpath) { ImageMetadata metadata;//from w w w . j ava 2 s . c om try { metadata = Imaging.getMetadata(new File(fullpath)); if (metadata != null) { if (!metadata.getClass().equals(GenericImageMetadata.class)) { JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; TiffImageMetadata exif = jpegMetadata.getExif(); if (exif != null) { isMetaDataPresent = true; } } else { GenericImageMetadata genMetadata = (GenericImageMetadata) metadata; if (genMetadata.getItems() != null && genMetadata.getItems().size() > 5) { isMetaDataPresent = true; } else if (genMetadata.getItems() != null && genMetadata.getItems().isEmpty()) { isMetaDataPresent = false; } } } } catch (IOException | ImageReadException imgException) { log.error(imgException.toString()); } }
From source file:com.cons.gps2exif.exif.ReadMetaData.java
public static void printMetaData(final File file) throws ImageReadException, IOException, IllegalArgumentException, IllegalAccessException { // get all metadata stored in EXIF format (ie. from JPEG or TIFF). ImageMetadata metadata = Imaging.getMetadata(file); if (!(metadata instanceof JpegImageMetadata)) { throw new RuntimeException("Only support " + JpegImageMetadata.class.getSimpleName()); }//from w ww . j ava 2 s .c o m JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; // JPEG EXIF metadata List<Field> exifTagfields = getTagInfoDefinedInClass(ExifTagConstants.class); System.out.println("=== " + ExifTagConstants.class.getSimpleName() + " ==="); printTagInfos(exifTagfields, jpegMetadata); // Tiff metadata List<Field> tiffTagfields = getTagInfoDefinedInClass(TiffTagConstants.class); System.out.println("=== " + TiffTagConstants.class.getSimpleName() + " ==="); printTagInfos(tiffTagfields, jpegMetadata); // Gps metadata List<Field> gpsTagfields = getTagInfoDefinedInClass(GpsTagConstants.class); System.out.println("=== " + GpsTagConstants.class.getSimpleName() + " ==="); printTagInfos(gpsTagfields, jpegMetadata); // simple interface to EXIF jpegMetadata TiffImageMetadata exifMetadata = jpegMetadata.getExif(); if (null != exifMetadata) { System.out.println("=== ExifMetadata ==="); jpegMetadata.getExif().getAllFields().stream().forEach(System.out::println); System.out.println(); } // All IImageMetadataItem List<ImageMetadataItem> items = jpegMetadata.getItems(); printIImageMetadataItems(items); }
From source file:at.ac.tuwien.qse.sepm.dao.repo.impl.JpegSerializer.java
private void readGps(JpegImageMetadata input, PhotoMetadata output) { try {//from w w w . java 2 s . com TiffImageMetadata tiffData = input.getExif(); if (tiffData == null) { LOGGER.debug("failed reading GPS since metadata contains no Exif"); return; } TiffImageMetadata.GPSInfo gps = input.getExif().getGPS(); if (gps == null) { LOGGER.debug("metadata contains no GPS"); return; } output.setLatitude(gps.getLatitudeAsDegreesNorth()); output.setLongitude(gps.getLongitudeAsDegreesEast()); LOGGER.debug("read GPS as longitude {} and latitude {}", output.getLongitude(), output.getLatitude()); } catch (ImageReadException ex) { LOGGER.warn("failed reading GPS data"); } }
From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java
private TiffOutputSet getOutputSet(final Path aFile) throws ImageReadException, IOException, ImageWriteException { final ImageMetadata metadata = Imaging.getMetadata(aFile.toFile()); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (null != jpegMetadata) { final TiffImageMetadata exif = jpegMetadata.getExif(); if (exif != null) { return exif.getOutputSet(); }/*from w ww. j a v a 2 s .c o m*/ } return new TiffOutputSet(); }