List of usage examples for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_APERTURE_VALUE
TagInfoRational EXIF_TAG_APERTURE_VALUE
To view the source code for org.apache.commons.imaging.formats.tiff.constants ExifTagConstants EXIF_TAG_APERTURE_VALUE.
Click Source Link
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. ///* w ww . j a v a 2 s . 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_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. ////from w w w .j a va2 s.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: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. //// w ww . j a va2s . 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: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 w w w. j a va 2s. com // 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:at.ac.tuwien.qse.sepm.service.impl.ExifServiceImpl.java
@Override public Exif getExif(Photo photo) throws ServiceException { File file = new File(photo.getPath()); String exposure = "not available"; double aperture = 0.0; double focalLength = 0.0; int iso = 0;/* w w w . ja v a2 s . c o m*/ boolean flash = false; String make = "not available"; String model = "not available"; double altitude = 0.0; try { final ImageMetadata metadata = Imaging.getMetadata(file); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_EXPOSURE_TIME) != null) { exposure = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_EXPOSURE_TIME) .getValueDescription().split(" ")[0]; } if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_APERTURE_VALUE) != null) { aperture = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_APERTURE_VALUE) .getDoubleValue(); } if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FOCAL_LENGTH) != null) { focalLength = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FOCAL_LENGTH) .getDoubleValue(); } if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_ISO) != null) { iso = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_ISO).getIntValue(); } if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FLASH) != null) { flash = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FLASH) .getIntValue() != 0; } if (jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MAKE) != null) { make = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MAKE) .getValueDescription(); } if (jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL) != null) { model = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL) .getValueDescription(); } if (jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_ALTITUDE) != null) { altitude = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_ALTITUDE) .getDoubleValue(); } return new Exif(photo.getId(), exposure, aperture, focalLength, iso, flash, make, model, altitude); } catch (IOException | ImageReadException e) { throw new ServiceException(e.getMessage(), e); } }
From source file:net.mozq.picto.core.ProcessCore.java
public static void findFiles(ProcessCondition processCondition, Consumer<ProcessData> processDataSetter, BooleanSupplier processStopper) throws IOException { Set<FileVisitOption> fileVisitOptionSet; if (processCondition.isFollowLinks()) { fileVisitOptionSet = EnumSet.of(FileVisitOption.FOLLOW_LINKS); } else {/*w w w .j a va2 s. com*/ fileVisitOptionSet = Collections.emptySet(); } Files.walkFileTree(processCondition.getSrcRootPath(), fileVisitOptionSet, processCondition.getDept(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.SKIP_SUBTREE; } if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } if (!processCondition.getPathFilter().accept(file, attrs)) { return FileVisitResult.SKIP_SUBTREE; } Path rootRelativeSubPath = processCondition.getSrcRootPath().relativize(file.getParent()); ImageMetadata imageMetadata = getImageMetadata(file); Date baseDate; if (processCondition.isChangeFileCreationDate() || processCondition.isChangeFileModifiedDate() || processCondition.isChangeFileAccessDate() || processCondition.isChangeExifDate()) { baseDate = getBaseDate(processCondition, file, attrs, imageMetadata); } else { baseDate = null; } String destSubPathname = processCondition.getDestSubPathFormat().format(varName -> { try { switch (varName) { case "Now": return new Date(); case "ParentSubPath": return rootRelativeSubPath.toString(); case "FileName": return file.getFileName().toString(); case "BaseName": return FileUtilz.getBaseName(file.getFileName().toString()); case "Extension": return FileUtilz.getExt(file.getFileName().toString()); case "Size": return Long.valueOf(Files.size(file)); case "CreationDate": return (processCondition.isChangeFileCreationDate()) ? baseDate : new Date(attrs.creationTime().toMillis()); case "ModifiedDate": return (processCondition.isChangeFileModifiedDate()) ? baseDate : new Date(attrs.lastModifiedTime().toMillis()); case "AccessDate": return (processCondition.isChangeFileAccessDate()) ? baseDate : new Date(attrs.lastAccessTime().toMillis()); case "PhotoTakenDate": return (processCondition.isChangeExifDate()) ? baseDate : getPhotoTakenDate(file, imageMetadata); case "Width": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_WIDTH); case "Height": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_LENGTH); case "FNumber": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FNUMBER); case "Aperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE); case "MaxAperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_MAX_APERTURE_VALUE); case "ISO": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_ISO); case "FocalLength": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH); // ? case "FocalLength35mm": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH_IN_35MM_FORMAT); case "ShutterSpeed": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE); case "Exposure": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE); // case "ExposureTime": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_TIME); // case "ExposureMode": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_MODE); case "ExposureProgram": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_PROGRAM); case "Brightness": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE); case "WhiteBalance": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_WHITE_BALANCE_1); case "LightSource": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_LIGHT_SOURCE); case "Lens": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS); case "LensMake": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MAKE); case "LensModel": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MODEL); case "LensSerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_SERIAL_NUMBER); case "Make": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MAKE); case "Model": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MODEL); case "SerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SERIAL_NUMBER); case "Software": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SOFTWARE); case "ProcessingSoftware": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_PROCESSING_SOFTWARE); case "OwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_OWNER_NAME); case "CameraOwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_CAMERA_OWNER_NAME); case "GPSLat": return getEXIFGpsLat(imageMetadata); case "GPSLatDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 0); case "GPSLatMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 1); case "GPSLatSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 2); case "GPSLatRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); case "GPSLon": return getEXIFGpsLon(imageMetadata); case "GPSLonDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 0); case "GPSLonMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 1); case "GPSLonSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 2); case "GPSLonRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); case "GPSAlt": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE); case "GPSAltRef": return getEXIFIntValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF); default: throw new PictoInvalidDestinationPathException(Messages .getString("message.warn.invalid.destSubPath.varName", varName)); } } catch (PictoException e) { throw e; } catch (Exception e) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destSubPath.pattern"), e); } }); Path destSubPath = processCondition.getDestRootPath().resolve(destSubPathname).normalize(); if (!destSubPath.startsWith(processCondition.getDestRootPath())) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destination.path", destSubPath)); } ProcessData processData = new ProcessData(); processData.setSrcPath(file); processData.setSrcFileAttributes(attrs); processData.setDestPath(destSubPath); processData.setBaseDate(baseDate); processDataSetter.accept(processData); return FileVisitResult.CONTINUE; } }); }
From source file:org.apache.commons.imaging.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. ///* w ww . ja v a 2s . com*/ // 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:org.apache.commons.imaging.examples.WriteExifMetadataExample.java
/** * This example illustrates how to add/update EXIF metadata in a JPEG file. * //www .j av a 2s . c o m * @param jpegImageFile * A source image file. * @param dst * The output file. * @throws IOException * @throws ImageReadException * @throws ImageWriteException */ public void changeExifMetadata(final File jpegImageFile, final File dst) throws IOException, ImageReadException, ImageWriteException { try (FileOutputStream fos = new FileOutputStream(dst); OutputStream os = new BufferedOutputStream(fos);) { TiffOutputSet outputSet = null; // note that metadata might be null if no metadata is found. final ImageMetadata metadata = Imaging.getMetadata(jpegImageFile); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (null != jpegMetadata) { // note that exif might be null if no Exif metadata is found. final TiffImageMetadata exif = jpegMetadata.getExif(); if (null != exif) { // TiffImageMetadata class is immutable (read-only). // TiffOutputSet class represents the Exif data to write. // // Usually, we want to update existing Exif metadata by // changing // the values of a few fields, or adding a field. // In these cases, it is easiest to use getOutputSet() to // start with a "copy" of the fields read from the image. outputSet = exif.getOutputSet(); } } // if file does not contain any exif metadata, we create an empty // set of exif metadata. Otherwise, we keep all of the other // existing tags. if (null == outputSet) { outputSet = new TiffOutputSet(); } { // Example of how to add a field/tag to the output set. // // Note that you should first remove the field/tag if it already // exists in this directory, or you may end up with duplicate // tags. See above. // // Certain fields/tags are expected in certain Exif directories; // Others can occur in more than one directory (and often have a // different meaning in different directories). // // TagInfo constants often contain a description of what // directories are associated with a given tag. // final TiffOutputDirectory exifDirectory = outputSet.getOrCreateExifDirectory(); // make sure to remove old value if present (this method will // not fail if the tag does not exist). exifDirectory.removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE); exifDirectory.add(ExifTagConstants.EXIF_TAG_APERTURE_VALUE, new RationalNumber(3, 10)); } { // Example of how to add/update GPS info to output set. // New York City final double longitude = -74.0; // 74 degrees W (in Degrees East) final double latitude = 40 + 43 / 60.0; // 40 degrees N (in Degrees // North) outputSet.setGPSInDegrees(longitude, latitude); } // printTagValue(jpegMetadata, TiffConstants.TIFF_TAG_DATE_TIME); new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet); } }
From source file:org.apache.commons.imaging.examples.WriteExifMetadataExample.java
/** * This example illustrates how to remove a tag (if present) from EXIF * metadata in a JPEG file.//from w w w .ja v a2 s . co m * * In this case, we remove the "aperture" tag from the EXIF metadata if * present. * * @param jpegImageFile * A source image file. * @param dst * The output file. * @throws IOException * @throws ImageReadException * @throws ImageWriteException */ public void removeExifTag(final File jpegImageFile, final File dst) throws IOException, ImageReadException, ImageWriteException { try (FileOutputStream fos = new FileOutputStream(dst); OutputStream os = new BufferedOutputStream(fos)) { TiffOutputSet outputSet = null; // note that metadata might be null if no metadata is found. final ImageMetadata metadata = Imaging.getMetadata(jpegImageFile); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (null != jpegMetadata) { // note that exif might be null if no Exif metadata is found. final TiffImageMetadata exif = jpegMetadata.getExif(); if (null != exif) { // TiffImageMetadata class is immutable (read-only). // TiffOutputSet class represents the Exif data to write. // // Usually, we want to update existing Exif metadata by // changing // the values of a few fields, or adding a field. // In these cases, it is easiest to use getOutputSet() to // start with a "copy" of the fields read from the image. outputSet = exif.getOutputSet(); } } if (null == outputSet) { // file does not contain any exif metadata. We don't need to // update the file; just copy it. FileUtils.copyFile(jpegImageFile, dst); return; } { // Example of how to remove a single tag/field. // There are two ways to do this. // Option 1: brute force // Note that this approach is crude: Exif data is organized in // directories. The same tag/field may appear in more than one // directory, and have different meanings in each. outputSet.removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE); // Option 2: precision // We know the exact directory the tag should appear in, in this // case the "exif" directory. // One complicating factor is that in some cases, manufacturers // will place the same tag in different directories. // To learn which directory a tag appears in, either refer to // the constants in ExifTagConstants.java or go to Phil Harvey's // EXIF website. final TiffOutputDirectory exifDirectory = outputSet.getExifDirectory(); if (null != exifDirectory) { exifDirectory.removeField(ExifTagConstants.EXIF_TAG_APERTURE_VALUE); } } new ExifRewriter().updateExifMetadataLossless(jpegImageFile, os, outputSet); } }