Search in sources :

Example 1 with ExifIFD0Directory

use of com.drew.metadata.exif.ExifIFD0Directory in project react-native-camera by lwansbrough.

the class RCTCameraModule method fixOrientation.

private byte[] fixOrientation(byte[] data) {
    final Metadata metadata;
    try {
        metadata = ImageMetadataReader.readMetadata(new BufferedInputStream(new ByteArrayInputStream(data)), data.length);
        final ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
        if (exifIFD0Directory == null) {
            return data;
        } else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
            final int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
            return rotate(data, exifOrientation);
        }
        return data;
    } catch (IOException | ImageProcessingException | MetadataException e) {
        e.printStackTrace();
        return data;
    }
}
Also used : ImageProcessingException(com.drew.imaging.ImageProcessingException) Metadata(com.drew.metadata.Metadata) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) MetadataException(com.drew.metadata.MetadataException)

Example 2 with ExifIFD0Directory

use of com.drew.metadata.exif.ExifIFD0Directory in project tika by apache.

the class ImageMetadataExtractorTest method testExifHandlerParseDateFallback.

@Test
public void testExifHandlerParseDateFallback() throws MetadataException {
    ExifIFD0Directory exif = mock(ExifIFD0Directory.class);
    when(exif.containsTag(ExifIFD0Directory.TAG_DATETIME)).thenReturn(true);
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getDefault(), Locale.ROOT);
    calendar.setTimeInMillis(0);
    calendar.set(1999, 0, 1, 0, 0, 0);
    when(exif.getDate(ExifIFD0Directory.TAG_DATETIME)).thenReturn(// jvm default timezone as in Metadata Extractor
    calendar.getTime());
    Metadata metadata = new Metadata();
    new ImageMetadataExtractor.ExifHandler().handle(exif, metadata);
    assertEquals("Should try EXIF Date/Time if Original is not set", "1999-01-01T00:00:00", metadata.get(TikaCoreProperties.CREATED));
}
Also used : ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) GregorianCalendar(java.util.GregorianCalendar) Metadata(org.apache.tika.metadata.Metadata) Test(org.junit.Test)

Example 3 with ExifIFD0Directory

use of com.drew.metadata.exif.ExifIFD0Directory in project structr by structr.

the class ImageHelper method getOrientation.

public static int getOrientation(final File originalImage) {
    try {
        final ExifIFD0Directory exifIFD0Directory = getMetadata(originalImage).getFirstDirectoryOfType(ExifIFD0Directory.class);
        if (exifIFD0Directory != null && exifIFD0Directory.hasTagName(ExifIFD0Directory.TAG_ORIENTATION)) {
            final Integer orientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
            originalImage.setProperty(StructrApp.key(Image.class, "orientation"), orientation);
            return orientation;
        }
    } catch (MetadataException | JSONException | FrameworkException ex) {
        logger.warn("Unable to store orientation information on image {} ({})", new Object[] { originalImage.getName(), originalImage.getId() });
    }
    return 1;
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) BufferedImage(java.awt.image.BufferedImage) Image(org.structr.web.entity.Image) MetadataException(com.drew.metadata.MetadataException)

Example 4 with ExifIFD0Directory

use of com.drew.metadata.exif.ExifIFD0Directory in project drill by apache.

the class GenericMetadataReader method read.

public void read(@NotNull FileType fileType, @NotNull FileStatus fileStatus, @NotNull Metadata metadata) {
    GenericMetadataDirectory directory = new GenericMetadataDirectory();
    boolean skipEPSPreview = false;
    directory.setLong(GenericMetadataDirectory.TAG_FILE_SIZE, fileStatus.getLen());
    // Add local time zone offset to store the last modified time as local time
    // just like TO_TIMESTAMP(UNIX_TIMESTAMP()) returns local time
    directory.setDate(GenericMetadataDirectory.TAG_FILE_DATE_TIME, new Date(fileStatus.getModificationTime() + TimeZone.getDefault().getRawOffset()));
    directory.setString(GenericMetadataDirectory.TAG_FORMAT, fileType.name().toUpperCase());
    for (Directory dir : metadata.getDirectories()) {
        if (dir instanceof JpegDirectory) {
            final JpegDirectory jpegDir = (JpegDirectory) dir;
            directory.setPixelWidth(jpegDir, JpegDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(jpegDir, JpegDirectory.TAG_IMAGE_HEIGHT);
            directory.setBitPerPixel(jpegDir, JpegDirectory.TAG_DATA_PRECISION, JpegDirectory.TAG_NUMBER_OF_COMPONENTS);
            continue;
        }
        if (dir instanceof JfifDirectory) {
            final JfifDirectory jfifDir = (JfifDirectory) dir;
            try {
                final int unit = jfifDir.getResUnits();
                if (unit == 1 || unit == 2) {
                    directory.setDPIWidth(jfifDir, JfifDirectory.TAG_RESX, unit == 1 ? 1.0 : 2.54);
                    directory.setDPIHeight(jfifDir, JfifDirectory.TAG_RESY, unit == 1 ? 1.0 : 2.54);
                }
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
        if (dir instanceof ExifIFD0Directory) {
            if (skipEPSPreview) {
                skipEPSPreview = false;
                continue;
            }
            final ExifIFD0Directory ifd0Dir = (ExifIFD0Directory) dir;
            directory.setPixelWidth(ifd0Dir, ExifIFD0Directory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(ifd0Dir, ExifIFD0Directory.TAG_IMAGE_HEIGHT);
            directory.setOrientation(ifd0Dir, ExifIFD0Directory.TAG_ORIENTATION);
            try {
                final int unit = ifd0Dir.getInt(ExifIFD0Directory.TAG_RESOLUTION_UNIT);
                if (unit == 2 || unit == 3) {
                    directory.setDPIWidth(ifd0Dir, ExifIFD0Directory.TAG_X_RESOLUTION, unit == 2 ? 1.0 : 2.54);
                    directory.setDPIHeight(ifd0Dir, ExifIFD0Directory.TAG_Y_RESOLUTION, unit == 2 ? 1.0 : 2.54);
                }
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            int[] bitPerSample = ifd0Dir.getIntArray(ExifIFD0Directory.TAG_BITS_PER_SAMPLE);
            if (bitPerSample != null) {
                int bitsPerPixel = 0;
                for (int n : bitPerSample) {
                    bitsPerPixel += n;
                }
                directory.setBitPerPixel(bitsPerPixel);
            }
            continue;
        }
        if (dir instanceof ExifSubIFDDirectory) {
            final ExifSubIFDDirectory subIFDDir = (ExifSubIFDDirectory) dir;
            directory.setPixelWidth(subIFDDir, ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH);
            directory.setPixelHeight(subIFDDir, ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT);
            continue;
        }
        if (dir instanceof PsdHeaderDirectory) {
            final PsdHeaderDirectory psdDir = (PsdHeaderDirectory) dir;
            directory.setPixelWidth(psdDir, PsdHeaderDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(psdDir, PsdHeaderDirectory.TAG_IMAGE_HEIGHT);
            directory.setBitPerPixel(psdDir, PsdHeaderDirectory.TAG_BITS_PER_CHANNEL, PsdHeaderDirectory.TAG_CHANNEL_COUNT);
            directory.setColorMode(psdDir, PsdHeaderDirectory.TAG_COLOR_MODE);
            continue;
        }
        if (dir instanceof PngDirectory) {
            final PngDirectory pngDir = (PngDirectory) dir;
            if (pngDir.getPngChunkType() == PngChunkType.IHDR) {
                directory.setPixelWidth(pngDir, PngDirectory.TAG_IMAGE_WIDTH);
                directory.setPixelHeight(pngDir, PngDirectory.TAG_IMAGE_HEIGHT);
                try {
                    int numOfComponent = 1;
                    int colorType = pngDir.getInt(PngDirectory.TAG_COLOR_TYPE);
                    if (colorType == PngColorType.IndexedColor.getNumericValue()) {
                        directory.setColorMode("Indexed");
                    } else if (colorType == PngColorType.Greyscale.getNumericValue()) {
                        directory.setColorMode("Grayscale");
                    } else if (colorType == PngColorType.GreyscaleWithAlpha.getNumericValue()) {
                        numOfComponent = 2;
                        directory.setColorMode("Grayscale");
                        directory.setAlpha(true);
                    } else if (colorType == PngColorType.TrueColor.getNumericValue()) {
                        numOfComponent = 3;
                    } else if (colorType == PngColorType.TrueColorWithAlpha.getNumericValue()) {
                        numOfComponent = 4;
                        directory.setAlpha(true);
                    }
                    directory.setBitPerPixel(pngDir.getInt(PngDirectory.TAG_BITS_PER_SAMPLE) * numOfComponent);
                } catch (MetadataException e) {
                // Nothing needs to be done
                }
                continue;
            }
            if (pngDir.getPngChunkType() == PngChunkType.pHYs) {
                try {
                    final int unit = pngDir.getInt(PngDirectory.TAG_UNIT_SPECIFIER);
                    if (unit == 1) {
                        directory.setDPIWidth(pngDir, PngDirectory.TAG_PIXELS_PER_UNIT_X, 0.0254);
                        directory.setDPIHeight(pngDir, PngDirectory.TAG_PIXELS_PER_UNIT_Y, 0.0254);
                    }
                } catch (MetadataException e) {
                // Nothing needs to be done
                }
                continue;
            }
            if (pngDir.getPngChunkType() == PngChunkType.tRNS) {
                directory.setAlpha(true);
                continue;
            }
            continue;
        }
        if (dir instanceof BmpHeaderDirectory) {
            final BmpHeaderDirectory bmpDir = (BmpHeaderDirectory) dir;
            directory.setPixelWidth(bmpDir, BmpHeaderDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(bmpDir, BmpHeaderDirectory.TAG_IMAGE_HEIGHT);
            directory.setDPIWidth(bmpDir, BmpHeaderDirectory.TAG_X_PIXELS_PER_METER, 0.0254);
            directory.setDPIHeight(bmpDir, BmpHeaderDirectory.TAG_Y_PIXELS_PER_METER, 0.0254);
            try {
                final int bitsPerPixel = bmpDir.getInt(BmpHeaderDirectory.TAG_BITS_PER_PIXEL);
                if (bitsPerPixel <= 8) {
                    directory.setColorMode("Indexed");
                }
                directory.setBitPerPixel(bitsPerPixel);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
        if (dir instanceof GifHeaderDirectory) {
            final GifHeaderDirectory gifDir = (GifHeaderDirectory) dir;
            directory.setPixelWidth(gifDir, GifHeaderDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(gifDir, GifHeaderDirectory.TAG_IMAGE_HEIGHT);
            directory.setColorMode("Indexed");
            directory.setBitPerPixel(gifDir, GifHeaderDirectory.TAG_BITS_PER_PIXEL);
            continue;
        }
        if (dir instanceof GifControlDirectory) {
            final GifControlDirectory gifControlDir = (GifControlDirectory) dir;
            directory.setAlpha(gifControlDir, GifControlDirectory.TAG_TRANSPARENT_COLOR_FLAG);
            continue;
        }
        if (dir instanceof IcoDirectory) {
            final IcoDirectory icoDir = (IcoDirectory) dir;
            directory.setPixelWidth(icoDir, IcoDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(icoDir, IcoDirectory.TAG_IMAGE_HEIGHT);
            try {
                if (icoDir.getInt(IcoDirectory.TAG_COLOUR_PALETTE_SIZE) != 0) {
                    directory.setColorMode("Indexed");
                }
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setBitPerPixel(icoDir, IcoDirectory.TAG_BITS_PER_PIXEL);
            directory.setAlpha(true);
            continue;
        }
        if (dir instanceof PcxDirectory) {
            final PcxDirectory pcxDir = (PcxDirectory) dir;
            try {
                directory.setPixelWidth(pcxDir.getInt(PcxDirectory.TAG_XMAX) - pcxDir.getInt(PcxDirectory.TAG_XMIN) + 1);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            try {
                directory.setPixelHeight(pcxDir.getInt(PcxDirectory.TAG_YMAX) - pcxDir.getInt(PcxDirectory.TAG_YMIN) + 1);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setDPIWidth(pcxDir, PcxDirectory.TAG_HORIZONTAL_DPI);
            directory.setDPIHeight(pcxDir, PcxDirectory.TAG_VERTICAL_DPI);
            directory.setBitPerPixel(pcxDir, PcxDirectory.TAG_BITS_PER_PIXEL, PcxDirectory.TAG_COLOR_PLANES);
            try {
                int colorPlanes = pcxDir.getInt(PcxDirectory.TAG_COLOR_PLANES);
                if (colorPlanes == 1) {
                    if (pcxDir.getInt(PcxDirectory.TAG_PALETTE_TYPE) == 2) {
                        directory.setColorMode("Grayscale");
                    } else {
                        directory.setColorMode("Indexed");
                    }
                }
                directory.setAlpha(colorPlanes == 4);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
        if (dir instanceof WavDirectory) {
            final WavDirectory wavDir = (WavDirectory) dir;
            directory.setColorMode("N/A");
            directory.setDuration(wavDir, WavDirectory.TAG_DURATION);
            directory.setAudioCodec(wavDir, WavDirectory.TAG_FORMAT);
            directory.setAudioSampleSize(wavDir, WavDirectory.TAG_BITS_PER_SAMPLE);
            directory.setAudioSampleRate(wavDir, WavDirectory.TAG_SAMPLES_PER_SEC);
        }
        if (dir instanceof AviDirectory) {
            final AviDirectory aviDir = (AviDirectory) dir;
            directory.setPixelWidth(aviDir, AviDirectory.TAG_WIDTH);
            directory.setPixelHeight(aviDir, AviDirectory.TAG_HEIGHT);
            directory.setDuration(aviDir, AviDirectory.TAG_DURATION);
            directory.setVideoCodec(aviDir, AviDirectory.TAG_VIDEO_CODEC);
            directory.setFrameRate(aviDir, AviDirectory.TAG_FRAMES_PER_SECOND);
            directory.setAudioCodec(aviDir, AviDirectory.TAG_AUDIO_CODEC);
            directory.setAudioSampleRate(aviDir, AviDirectory.TAG_SAMPLES_PER_SECOND);
            continue;
        }
        if (dir instanceof WebpDirectory) {
            final WebpDirectory webpDir = (WebpDirectory) dir;
            directory.setPixelWidth(webpDir, WebpDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(webpDir, WebpDirectory.TAG_IMAGE_HEIGHT);
            directory.setAlpha(webpDir, WebpDirectory.TAG_HAS_ALPHA);
            continue;
        }
        if (dir instanceof QuickTimeVideoDirectory) {
            final QuickTimeVideoDirectory qtVideoDir = (QuickTimeVideoDirectory) dir;
            directory.setPixelWidth(qtVideoDir, QuickTimeVideoDirectory.TAG_WIDTH);
            directory.setPixelHeight(qtVideoDir, QuickTimeVideoDirectory.TAG_HEIGHT);
            directory.setDPIWidth(qtVideoDir, QuickTimeVideoDirectory.TAG_HORIZONTAL_RESOLUTION);
            directory.setDPIHeight(qtVideoDir, QuickTimeVideoDirectory.TAG_VERTICAL_RESOLUTION);
            try {
                int bitsPerPixel = qtVideoDir.getInt(QuickTimeVideoDirectory.TAG_DEPTH) % 32;
                directory.setBitPerPixel(bitsPerPixel);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setDuration(qtVideoDir, QuickTimeVideoDirectory.TAG_DURATION);
            directory.setVideoCodec(qtVideoDir, QuickTimeVideoDirectory.TAG_COMPRESSION_TYPE);
            directory.setFrameRate(qtVideoDir, QuickTimeVideoDirectory.TAG_FRAME_RATE);
            continue;
        }
        if (dir instanceof QuickTimeSoundDirectory) {
            final QuickTimeSoundDirectory qtSoundDir = (QuickTimeSoundDirectory) dir;
            directory.setAudioCodec(qtSoundDir, QuickTimeSoundDirectory.TAG_AUDIO_FORMAT);
            directory.setAudioSampleSize(qtSoundDir, QuickTimeSoundDirectory.TAG_AUDIO_SAMPLE_SIZE);
            directory.setAudioSampleRate(qtSoundDir, QuickTimeSoundDirectory.TAG_AUDIO_SAMPLE_RATE);
            continue;
        }
        if (dir instanceof QuickTimeDirectory) {
            final QuickTimeDirectory qtDir = (QuickTimeDirectory) dir;
            directory.setDuration(qtDir, QuickTimeDirectory.TAG_DURATION);
            continue;
        }
        if (dir instanceof Mp4VideoDirectory) {
            final Mp4VideoDirectory mp4VideoDir = (Mp4VideoDirectory) dir;
            directory.setPixelWidth(mp4VideoDir, Mp4VideoDirectory.TAG_WIDTH);
            directory.setPixelHeight(mp4VideoDir, Mp4VideoDirectory.TAG_HEIGHT);
            directory.setDPIWidth(mp4VideoDir, Mp4VideoDirectory.TAG_HORIZONTAL_RESOLUTION);
            directory.setDPIHeight(mp4VideoDir, Mp4VideoDirectory.TAG_VERTICAL_RESOLUTION);
            try {
                int bitsPerPixel = mp4VideoDir.getInt(Mp4VideoDirectory.TAG_DEPTH) % 32;
                directory.setBitPerPixel(bitsPerPixel);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setDuration(mp4VideoDir, Mp4VideoDirectory.TAG_DURATION);
            directory.setVideoCodec(mp4VideoDir, Mp4VideoDirectory.TAG_COMPRESSION_TYPE);
            directory.setFrameRate(mp4VideoDir, Mp4VideoDirectory.TAG_FRAME_RATE);
            continue;
        }
        if (dir instanceof Mp4SoundDirectory) {
            final Mp4SoundDirectory mp4SoundDir = (Mp4SoundDirectory) dir;
            directory.setAudioCodec(mp4SoundDir, Mp4SoundDirectory.TAG_AUDIO_FORMAT);
            directory.setAudioSampleSize(mp4SoundDir, Mp4SoundDirectory.TAG_AUDIO_SAMPLE_SIZE);
            directory.setAudioSampleRate(mp4SoundDir, Mp4SoundDirectory.TAG_AUDIO_SAMPLE_RATE);
            continue;
        }
        if (dir instanceof Mp4Directory) {
            final Mp4Directory mp4Dir = (Mp4Directory) dir;
            directory.setDuration(mp4Dir, Mp4Directory.TAG_DURATION);
            continue;
        }
        if (dir instanceof EpsDirectory) {
            final EpsDirectory epsDir = (EpsDirectory) dir;
            directory.setPixelWidth(epsDir, EpsDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(epsDir, EpsDirectory.TAG_IMAGE_HEIGHT);
            try {
                int bitsPerPixel = 24;
                int colorType = epsDir.getInt(EpsDirectory.TAG_COLOR_TYPE);
                if (colorType == 1) {
                    String imageData = epsDir.getString(EpsDirectory.TAG_IMAGE_DATA);
                    if (imageData != null && imageData.split(" ")[2].equals("1")) {
                        bitsPerPixel = 1;
                        directory.setColorMode("Bitmap");
                    } else {
                        bitsPerPixel = 8;
                        directory.setColorMode("Grayscale");
                    }
                } else if (colorType == 2) {
                    directory.setColorMode("Lab");
                } else if (colorType == 4) {
                    bitsPerPixel = 32;
                    directory.setColorMode("CMYK");
                }
                directory.setBitPerPixel(bitsPerPixel);
                skipEPSPreview = epsDir.containsTag(EpsDirectory.TAG_TIFF_PREVIEW_SIZE);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
    }
    // Set default value if empty
    directory.setPixelWidth(0);
    directory.setPixelHeight(0);
    directory.setOrientation(0);
    directory.setDPIWidth(0.0);
    directory.setDPIHeight(0.0);
    directory.setColorMode("RGB");
    directory.setBitPerPixel(0);
    directory.setAlpha(false);
    directory.setDuration(0);
    directory.setVideoCodec("Unknown");
    directory.setFrameRate(0.0);
    directory.setAudioCodec("Unknown");
    directory.setAudioSampleSize(0);
    directory.setAudioSampleRate(0.0);
    metadata.addDirectory(directory);
}
Also used : GifControlDirectory(com.drew.metadata.gif.GifControlDirectory) PngDirectory(com.drew.metadata.png.PngDirectory) QuickTimeSoundDirectory(com.drew.metadata.mov.media.QuickTimeSoundDirectory) WebpDirectory(com.drew.metadata.webp.WebpDirectory) MetadataException(com.drew.metadata.MetadataException) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) QuickTimeVideoDirectory(com.drew.metadata.mov.media.QuickTimeVideoDirectory) PcxDirectory(com.drew.metadata.pcx.PcxDirectory) GifHeaderDirectory(com.drew.metadata.gif.GifHeaderDirectory) PsdHeaderDirectory(com.drew.metadata.photoshop.PsdHeaderDirectory) EpsDirectory(com.drew.metadata.eps.EpsDirectory) AviDirectory(com.drew.metadata.avi.AviDirectory) GifControlDirectory(com.drew.metadata.gif.GifControlDirectory) Mp4Directory(com.drew.metadata.mp4.Mp4Directory) WebpDirectory(com.drew.metadata.webp.WebpDirectory) BmpHeaderDirectory(com.drew.metadata.bmp.BmpHeaderDirectory) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) Directory(com.drew.metadata.Directory) JfifDirectory(com.drew.metadata.jfif.JfifDirectory) QuickTimeDirectory(com.drew.metadata.mov.QuickTimeDirectory) IcoDirectory(com.drew.metadata.ico.IcoDirectory) JpegDirectory(com.drew.metadata.jpeg.JpegDirectory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) PngDirectory(com.drew.metadata.png.PngDirectory) Mp4VideoDirectory(com.drew.metadata.mp4.media.Mp4VideoDirectory) QuickTimeVideoDirectory(com.drew.metadata.mov.media.QuickTimeVideoDirectory) Mp4SoundDirectory(com.drew.metadata.mp4.media.Mp4SoundDirectory) PsdHeaderDirectory(com.drew.metadata.photoshop.PsdHeaderDirectory) PcxDirectory(com.drew.metadata.pcx.PcxDirectory) GifHeaderDirectory(com.drew.metadata.gif.GifHeaderDirectory) QuickTimeSoundDirectory(com.drew.metadata.mov.media.QuickTimeSoundDirectory) WavDirectory(com.drew.metadata.wav.WavDirectory) QuickTimeDirectory(com.drew.metadata.mov.QuickTimeDirectory) Mp4VideoDirectory(com.drew.metadata.mp4.media.Mp4VideoDirectory) Mp4SoundDirectory(com.drew.metadata.mp4.media.Mp4SoundDirectory) Mp4Directory(com.drew.metadata.mp4.Mp4Directory) Date(java.util.Date) AviDirectory(com.drew.metadata.avi.AviDirectory) WavDirectory(com.drew.metadata.wav.WavDirectory) JpegDirectory(com.drew.metadata.jpeg.JpegDirectory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) BmpHeaderDirectory(com.drew.metadata.bmp.BmpHeaderDirectory) EpsDirectory(com.drew.metadata.eps.EpsDirectory) IcoDirectory(com.drew.metadata.ico.IcoDirectory) JfifDirectory(com.drew.metadata.jfif.JfifDirectory)

Example 5 with ExifIFD0Directory

use of com.drew.metadata.exif.ExifIFD0Directory in project drill by apache.

the class ImageBatchReader method processExtenalMetadata.

private void processExtenalMetadata() {
    boolean skipEPSPreview = false;
    for (Directory directory : metadata.getDirectories()) {
        // Skip the `Generic Metadata Directory`
        String dictName = ImageMetadataUtils.formatName(directory.getName());
        if (directory instanceof GenericMetadataDirectory) {
            continue;
        }
        if (directory instanceof ExifIFD0Directory && skipEPSPreview) {
            skipEPSPreview = false;
            continue;
        }
        if (directory instanceof EpsDirectory) {
            // If an EPS file contains a TIFF preview, skip the next IFD0
            skipEPSPreview = directory.containsTag(EpsDirectory.TAG_TIFF_PREVIEW_SIZE);
        }
        // Process the `External Metadata Directory`
        MapColumnDefn columnDefn = new MapColumnDefn(dictName).builder(loader);
        ImageDirectoryProcessor.processDirectory(columnDefn, directory, metadata, config);
        // Continue to process XmpDirectory if exists
        if (directory instanceof XmpDirectory) {
            ImageDirectoryProcessor.processXmpDirectory(columnDefn, (XmpDirectory) directory);
        }
    }
}
Also used : XmpDirectory(com.drew.metadata.xmp.XmpDirectory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) EpsDirectory(com.drew.metadata.eps.EpsDirectory) EpsDirectory(com.drew.metadata.eps.EpsDirectory) Directory(com.drew.metadata.Directory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) XmpDirectory(com.drew.metadata.xmp.XmpDirectory)

Aggregations

ExifIFD0Directory (com.drew.metadata.exif.ExifIFD0Directory)13 MetadataException (com.drew.metadata.MetadataException)8 ImageProcessingException (com.drew.imaging.ImageProcessingException)5 Metadata (com.drew.metadata.Metadata)5 ExifSubIFDDirectory (com.drew.metadata.exif.ExifSubIFDDirectory)5 IOException (java.io.IOException)5 Directory (com.drew.metadata.Directory)3 GpsDirectory (com.drew.metadata.exif.GpsDirectory)3 BufferedImage (java.awt.image.BufferedImage)3 EpsDirectory (com.drew.metadata.eps.EpsDirectory)2 PngDirectory (com.drew.metadata.png.PngDirectory)2 Date (java.util.Date)2 Metadata (org.apache.tika.metadata.Metadata)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 FrameworkException (org.structr.common.error.FrameworkException)2 Image (org.structr.web.entity.Image)2 XMPException (com.adobe.internal.xmp.XMPException)1 Tag (com.drew.metadata.Tag)1