Search in sources :

Example 1 with GpsDirectory

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;
}
Also used : GpsDirectory(com.drew.metadata.exif.GpsDirectory) GpsDescriptor(com.drew.metadata.exif.GpsDescriptor) LineString(de.micromata.opengis.kml.v_2_2_0.LineString)

Example 2 with GpsDirectory

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;
}
Also used : GpsDirectory(com.drew.metadata.exif.GpsDirectory) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) JSONObject(org.json.JSONObject) Metadata(com.drew.metadata.Metadata) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) BufferedImage(java.awt.image.BufferedImage) Image(org.structr.web.entity.Image) JSONException(org.json.JSONException) FrameworkException(org.structr.common.error.FrameworkException) ImageProcessingException(com.drew.imaging.ImageProcessingException) MetadataException(com.drew.metadata.MetadataException) IOException(java.io.IOException)

Example 3 with GpsDirectory

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());
        }
    }
}
Also used : GpsDirectory(com.drew.metadata.exif.GpsDirectory) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) TimeZone(java.util.TimeZone) PngDirectory(com.drew.metadata.png.PngDirectory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) Tag(com.drew.metadata.Tag) XMPException(com.adobe.internal.xmp.XMPException)

Aggregations

GpsDirectory (com.drew.metadata.exif.GpsDirectory)3 ExifIFD0Directory (com.drew.metadata.exif.ExifIFD0Directory)2 ExifSubIFDDirectory (com.drew.metadata.exif.ExifSubIFDDirectory)2 XMPException (com.adobe.internal.xmp.XMPException)1 ImageProcessingException (com.drew.imaging.ImageProcessingException)1 Metadata (com.drew.metadata.Metadata)1 MetadataException (com.drew.metadata.MetadataException)1 Tag (com.drew.metadata.Tag)1 GpsDescriptor (com.drew.metadata.exif.GpsDescriptor)1 PngDirectory (com.drew.metadata.png.PngDirectory)1 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 TimeZone (java.util.TimeZone)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 FrameworkException (org.structr.common.error.FrameworkException)1 Image (org.structr.web.entity.Image)1