Search in sources :

Example 1 with RationalNumber

use of org.apache.commons.imaging.common.RationalNumber in project Lucee by lucee.

the class Metadata method val.

private static Object val(Object value) {
    if (value == null)
        return null;
    if (value instanceof CharSequence)
        return value.toString();
    if (value instanceof Number)
        return ((Number) value).doubleValue();
    if (Decision.isNativeArray(value) && !(value instanceof Object[]))
        return value;
    if (value instanceof Object[]) {
        Array trg = new ArrayImpl();
        Object[] arr = (Object[]) value;
        for (Object obj : arr) {
            trg.appendEL(val(obj));
        }
        return trg;
    }
    if (value instanceof RationalNumber) {
        RationalNumber rn = (RationalNumber) value;
        return rn.toDisplayString();
    }
    return value;
}
Also used : Array(lucee.runtime.type.Array) RationalNumber(org.apache.commons.imaging.common.RationalNumber) ArrayImpl(lucee.runtime.type.ArrayImpl) RationalNumber(org.apache.commons.imaging.common.RationalNumber)

Example 2 with RationalNumber

use of org.apache.commons.imaging.common.RationalNumber 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);
    }
}
Also used : TiffField(org.apache.commons.imaging.formats.tiff.TiffField) TiffImageMetadata(org.apache.commons.imaging.formats.tiff.TiffImageMetadata) StructImpl(lucee.runtime.type.StructImpl) RationalNumber(org.apache.commons.imaging.common.RationalNumber) Struct(lucee.runtime.type.Struct)

Aggregations

RationalNumber (org.apache.commons.imaging.common.RationalNumber)2 Array (lucee.runtime.type.Array)1 ArrayImpl (lucee.runtime.type.ArrayImpl)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 TiffField (org.apache.commons.imaging.formats.tiff.TiffField)1 TiffImageMetadata (org.apache.commons.imaging.formats.tiff.TiffImageMetadata)1