Example usage for org.apache.commons.imaging.common IImageMetadata getItems

List of usage examples for org.apache.commons.imaging.common IImageMetadata getItems

Introduction

In this page you can find the example usage for org.apache.commons.imaging.common IImageMetadata getItems.

Prototype

public List<? extends IImageMetadataItem> getItems();

Source Link

Usage

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

private static void fill(String format, InputStream is, Struct info) throws ImageReadException, IOException {
    // get all metadata stored in EXIF format (ie. from JPEG or TIFF).
    IImageMetadata metadata = Imaging.getMetadata(is, "test." + format);
    if (metadata == null)
        return;//from  ww  w .j  a va 2s.c om

    // System.out.println(metadata);

    if (metadata instanceof JpegImageMetadata) {
        final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;

        try {
            set(jpegMetadata.getItems(), info, null);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
        try {
            set(metadata.getItems(), info, null);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }

        // Photoshop
        if (metadata instanceof JpegImageMetadata) {
            JpegPhotoshopMetadata photoshop = ((JpegImageMetadata) metadata).getPhotoshop();
            if (photoshop != null) {
                try {

                    List<? extends IImageMetadataItem> list = photoshop.getItems();
                    if (list != null && !list.isEmpty()) {
                        Struct ps = new StructImpl();
                        info.setEL("photoshop", ps);
                        try {
                            set(list, ps, null);
                        } catch (Throwable t) {
                            ExceptionUtil.rethrowIfNecessary(t);
                        }
                    }
                } catch (Throwable t) {
                    ExceptionUtil.rethrowIfNecessary(t);
                }
            }
        }

        // EXIF
        if (jpegMetadata != null) {
            Struct exif = new StructImpl();
            info.setEL("exif", exif);
            try {
                set(jpegMetadata.getExif().getItems(), exif, null);
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
            }
        }
        // GPS
        try {
            gps(jpegMetadata, info);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }

    }
}