use of org.apache.commons.imaging.formats.tiff.TiffImageMetadata in project Lucee by lucee.
the class Metadata method gps.
private static void gps(JpegImageMetadata jpegMetadata, Struct info) throws ImageReadException {
Struct gps = new StructImpl();
info.setEL("gps", gps);
info = gps;
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);
}
}
Aggregations