use of com.drew.metadata.exif.GpsDirectory in project java-mapollage by trixon.
the class Operation method getPlacemarkDescription.
private String getPlacemarkDescription(File file, PhotoInfo photoInfo, Date exifDate) throws IOException {
GpsDirectory gpsDirectory = photoInfo.getGpsDirectory();
GpsDescriptor gpsDescriptor = null;
if (gpsDirectory != null) {
gpsDescriptor = new GpsDescriptor(gpsDirectory);
}
String desc = "";
switch(mProfileDescription.getMode()) {
case CUSTOM:
desc = mProfileDescription.getCustomValue();
break;
case EXTERNAL:
desc = getExternalDescription(file);
break;
case NONE:
// Do nothing
break;
case STATIC:
desc = getStaticDescription();
break;
}
if (mProfileDescription.getMode() != ProfileDescription.DescriptionMode.NONE) {
if (StringUtils.containsIgnoreCase(desc, DescriptionSegment.PHOTO.toString())) {
desc = StringUtils.replace(desc, DescriptionSegment.PHOTO.toString(), getDescPhoto(file, photoInfo.getOrientation()));
}
desc = StringUtils.replace(desc, DescriptionSegment.FILENAME.toString(), file.getName());
desc = StringUtils.replace(desc, DescriptionSegment.DATE.toString(), mDateFormatDate.format(exifDate));
if (gpsDirectory != null && gpsDescriptor != null) {
desc = StringUtils.replace(desc, DescriptionSegment.ALTITUDE.toString(), gpsDescriptor.getGpsAltitudeDescription());
desc = StringUtils.replace(desc, DescriptionSegment.COORDINATE.toString(), gpsDescriptor.getDegreesMinutesSecondsDescription());
String bearing = gpsDescriptor.getGpsDirectionDescription(GpsDirectory.TAG_DEST_BEARING);
desc = StringUtils.replace(desc, DescriptionSegment.BEARING.toString(), bearing == null ? "" : bearing);
} else {
desc = StringUtils.replace(desc, DescriptionSegment.ALTITUDE.toString(), "");
desc = StringUtils.replace(desc, DescriptionSegment.COORDINATE.toString(), "");
desc = StringUtils.replace(desc, DescriptionSegment.BEARING.toString(), "");
}
desc = getSafeXmlString(desc);
}
return desc;
}
use of com.drew.metadata.exif.GpsDirectory in project structr by structr.
the class ImageHelper method getExifData.
public static JSONObject getExifData(final File originalImage) {
final JSONObject exifDataJson = new JSONObject();
try {
final Metadata metadata = getMetadata(originalImage);
final ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
final ExifSubIFDDirectory exifSubIFDDirectory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
final GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);
if (exifIFD0Directory != null) {
final JSONObject exifIFD0DataJson = new JSONObject();
exifIFD0Directory.getTags().forEach((tag) -> {
exifIFD0DataJson.put(tag.getTagName(), exifIFD0Directory.getDescription(tag.getTagType()));
});
originalImage.setProperty(StructrApp.key(Image.class, "exifIFD0Data"), exifIFD0DataJson.toString());
exifDataJson.putOnce("exifIFD0Data", exifIFD0DataJson);
}
if (exifSubIFDDirectory != null) {
final JSONObject exifSubIFDDataJson = new JSONObject();
exifSubIFDDirectory.getTags().forEach((tag) -> {
exifSubIFDDataJson.put(tag.getTagName(), exifSubIFDDirectory.getDescription(tag.getTagType()));
});
originalImage.setProperty(StructrApp.key(Image.class, "exifSubIFDData"), exifSubIFDDataJson.toString());
exifDataJson.putOnce("exifSubIFDData", exifSubIFDDataJson);
}
if (gpsDirectory != null) {
final JSONObject exifGpsDataJson = new JSONObject();
gpsDirectory.getTags().forEach((tag) -> {
exifGpsDataJson.put(tag.getTagName(), gpsDirectory.getDescription(tag.getTagType()));
});
originalImage.setProperty(StructrApp.key(Image.class, "gpsData"), exifGpsDataJson.toString());
exifDataJson.putOnce("gpsData", exifGpsDataJson);
}
return exifDataJson;
} catch (Exception ex) {
logger.warn("Unable to extract EXIF metadata.", ex);
}
return null;
}
use of com.drew.metadata.exif.GpsDirectory in project drill by apache.
the class ImageDirectoryProcessor method processDirectory.
protected static void processDirectory(final MapColumnDefn writer, final Directory directory, final Metadata metadata, final ImageFormatConfig config) {
TimeZone timeZone = (config.getTimeZone() != null) ? TimeZone.getTimeZone(config.getTimeZone()) : TimeZone.getDefault();
for (Tag tag : directory.getTags()) {
try {
final int tagType = tag.getTagType();
Object value;
if (config.isDescriptive() || ImageMetadataUtils.isDescriptionTag(directory, tagType)) {
value = directory.getDescription(tagType);
if (directory instanceof PngDirectory) {
if (((PngDirectory) directory).getPngChunkType().areMultipleAllowed()) {
value = new String[] { (String) value };
}
}
} else {
value = directory.getObject(tagType);
if (directory instanceof ExifIFD0Directory && tagType == ExifIFD0Directory.TAG_DATETIME) {
ExifSubIFDDirectory exifSubIFDDir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
String subsecond = null;
if (exifSubIFDDir != null) {
subsecond = exifSubIFDDir.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME);
}
value = directory.getDate(tagType, subsecond, timeZone);
} else if (directory instanceof ExifSubIFDDirectory) {
if (tagType == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL) {
value = ((ExifSubIFDDirectory) directory).getDateOriginal(timeZone);
} else if (tagType == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED) {
value = ((ExifSubIFDDirectory) directory).getDateDigitized(timeZone);
}
} else if (directory instanceof GpsDirectory) {
if (tagType == GpsDirectory.TAG_LATITUDE) {
value = ((GpsDirectory) directory).getGeoLocation().getLatitude();
} else if (tagType == GpsDirectory.TAG_LONGITUDE) {
value = ((GpsDirectory) directory).getGeoLocation().getLongitude();
}
}
if (ImageMetadataUtils.isVersionTag(directory, tagType)) {
value = directory.getString(tagType, "US-ASCII");
} else if (ImageMetadataUtils.isDateTag(directory, tagType)) {
value = directory.getDate(tagType, timeZone);
}
}
processValue(writer, ImageMetadataUtils.formatName(tag.getTagName()), value);
} catch (Exception skipped) {
logger.warn("Error in processing image directory : {}", skipped.getMessage());
}
}
}
Aggregations