Example usage for org.apache.commons.imaging.formats.jpeg JpegImageMetadata findEXIFValueWithExactMatch

List of usage examples for org.apache.commons.imaging.formats.jpeg JpegImageMetadata findEXIFValueWithExactMatch

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.jpeg JpegImageMetadata findEXIFValueWithExactMatch.

Prototype

public TiffField findEXIFValueWithExactMatch(final TagInfo tagInfo) 

Source Link

Usage

From source file:MetadataExample.java

private static void printTagValue(JpegImageMetadata jpegMetadata, TagInfo tagInfo) {
    TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
    if (field == null) {
        System.out.println(tagInfo.name + ": " + "Not Found.");
    } else {//from  w w w  .j av a 2 s  .  c o  m
        System.out.println(tagInfo.name + ": " + field.getValueDescription());
    }
}

From source file:de.tehame.examples.MetadataExample.java

private static void printTagValue(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo) {
    final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
    if (field == null) {
        System.out.println(tagInfo.name + ": " + "Not Found.");
    } else {/* w  w  w.j  av  a  2s  .co m*/
        System.out.println(tagInfo.name + ": " + field.getValueDescription());
    }
}

From source file:de.aikiit.fotorenamer.image.MetaDataExtractor.java

/**
 * Returns the requested tag as String from the image file.
 *
 * @param image Image file to extract Metadata from.
 * @param tag   Tag to extract from the given file, @see TiffConstants
 * @return Returns exif tag value, in case of any errors the value is an
 * empty String./*from   w w w . ja  v  a  2s  .c  o m*/
 * @throws IOException        if file cannot be accessed.
 * @throws ImageReadException if an error occurred during image processing.
 */
public static String getExifMetadata(final File image, final TagInfo tag)
        throws IOException, ImageReadException {
    assert image != null : "Parameter image must not be null";
    assert tag != null : "Parameter tag must not be null";

    String result = EMPTY_STRING;
    ImageMetadata metadata = Imaging.getMetadata(image);

    /*
            for(ImageMetadata.ImageMetadataItem item:metadata.getItems()) {
    System.out.println("WWW: " + item.getSelectedDirectory());
            }
      */
    if (metadata instanceof JpegImageMetadata) {
        JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
        TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tag);
        if (field != null) {
            result = field.getValueDescription();
            LOG.info("extraction of " + tag.getDescription() + " yields " + result);
        }
    }
    return (result == null ? EMPTY_STRING : result);
}

From source file:name.hampton.mike.gallery.MetadataExtractor.java

private static void recordTagValue(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo,
        Map<String, Object> out) {
    final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
    if (field != null) {
        out.put(tagInfo.name, field.getValueDescription());
    }//from  www  . j  a  v a  2s.c  o  m
}

From source file:lucee.runtime.img.Metadata.java

private static void set(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo, Struct info)
        throws ImageReadException {
    final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
    if (field != null) {
        if (!info.containsKey(tagInfo.name)) {
            Object val = val(field.getValue());
            if (val != null)
                info.setEL(tagInfo.name, val);
        }/*  w  w w . j av  a  2  s  . c  om*/
    }
}

From source file:com.mycompany.jpegrenamer.MetaDataReader.java

private static void printTagValue(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo) {
    final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
    if (field == null) {
        logger.info(tagInfo.name + ": " + "Not Found.");
    } else {/*from   www  . j  a  v a2 s  .c o  m*/
        logger.info(tagInfo.name + ": " + field.getValueDescription());
    }
}

From source file:com.mycompany.jpegrenamer.MetaDataReader.java

private static String getTagValue(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo) {
    final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
    if (field == null) {
        return "";
    } else {//from www .j a v a  2s.com
        return field.getValueDescription();
    }
}

From source file:com.mycompany.jpegrenamer.MetaDataReader.java

private static Date getDateTagValue(final JpegImageMetadata jpegMetadata, final TagInfo tagInfo)
        throws ImageReadException {
    final TiffField field = jpegMetadata.findEXIFValueWithExactMatch(tagInfo);
    if (field == null) {
        return null;
    } else {//from   w w  w  .j a  va2  s  .co  m
        Date d = (Date) field.getValue();
        return d;
    }
}

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;//from   w ww .  j  a  v  a  2  s  .  c om
    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: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 .jav  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);
    }
}