Search in sources :

Example 6 with MetadataException

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

the class MutableImage method fixOrientation.

public void fixOrientation() throws ImageMutationFailedException {
    try {
        Metadata metadata = originalImageMetaData();
        ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
        if (exifIFD0Directory == null) {
            return;
        } else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
            int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
            if (exifOrientation != 1) {
                rotate(exifOrientation);
                exifIFD0Directory.setInt(ExifIFD0Directory.TAG_ORIENTATION, 1);
            }
        }
    } catch (ImageProcessingException | IOException | MetadataException e) {
        throw new ImageMutationFailedException("failed to fix orientation", e);
    }
}
Also used : ImageProcessingException(com.drew.imaging.ImageProcessingException) Metadata(com.drew.metadata.Metadata) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) IOException(java.io.IOException) MetadataException(com.drew.metadata.MetadataException)

Example 7 with MetadataException

use of com.drew.metadata.MetadataException in project tika by apache.

the class ImageMetadataExtractor method parseJpeg.

public void parseJpeg(File file) throws IOException, SAXException, TikaException {
    try {
        com.drew.metadata.Metadata jpegMetadata = JpegMetadataReader.readMetadata(file);
        handle(jpegMetadata);
    } catch (JpegProcessingException e) {
        throw new TikaException("Can't read JPEG metadata", e);
    } catch (MetadataException e) {
        throw new TikaException("Can't read JPEG metadata", e);
    }
}
Also used : TikaException(org.apache.tika.exception.TikaException) JpegProcessingException(com.drew.imaging.jpeg.JpegProcessingException) MetadataException(com.drew.metadata.MetadataException)

Example 8 with MetadataException

use of com.drew.metadata.MetadataException in project tika by apache.

the class ImageMetadataExtractor method parseWebP.

public void parseWebP(File file) throws IOException, TikaException {
    try {
        com.drew.metadata.Metadata webPMetadata = new com.drew.metadata.Metadata();
        webPMetadata = WebpMetadataReader.readMetadata(file);
        handle(webPMetadata);
    } catch (IOException e) {
        throw e;
    } catch (RiffProcessingException e) {
        throw new TikaException("Can't process Riff data", e);
    } catch (MetadataException e) {
        throw new TikaException("Can't process Riff data", e);
    }
}
Also used : TikaException(org.apache.tika.exception.TikaException) Metadata(org.apache.tika.metadata.Metadata) XMPMetadata(org.apache.jempbox.xmp.XMPMetadata) RiffProcessingException(com.drew.imaging.riff.RiffProcessingException) IOException(java.io.IOException) MetadataException(com.drew.metadata.MetadataException)

Example 9 with MetadataException

use of com.drew.metadata.MetadataException in project react-native-camera by react-native-community.

the class MutableImage method fixOrientation.

public void fixOrientation() throws ImageMutationFailedException {
    try {
        Metadata metadata = originalImageMetaData();
        ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
        if (exifIFD0Directory == null) {
            return;
        } else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
            int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
            if (exifOrientation != 1) {
                rotate(exifOrientation);
                exifIFD0Directory.setInt(ExifIFD0Directory.TAG_ORIENTATION, 1);
            }
        }
    } catch (ImageProcessingException | IOException | MetadataException e) {
        throw new ImageMutationFailedException("failed to fix orientation", e);
    }
}
Also used : ImageProcessingException(com.drew.imaging.ImageProcessingException) Metadata(com.drew.metadata.Metadata) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) IOException(java.io.IOException) MetadataException(com.drew.metadata.MetadataException)

Example 10 with MetadataException

use of com.drew.metadata.MetadataException in project java-mapollage by trixon.

the class PhotoInfo method init.

public void init() throws ImageProcessingException, IOException {
    try {
        mMetadata = ImageMetadataReader.readMetadata(mFile);
        mExifDirectory = mMetadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
        mGpsDirectory = mMetadata.getFirstDirectoryOfType(GpsDirectory.class);
        mGeoLocation = getGeoLocation();
        try {
            ExifIFD0Directory rotationDirectory = mMetadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
            mOrientation = rotationDirectory.getInt(ExifSubIFDDirectory.TAG_ORIENTATION);
        } catch (MetadataException | NullPointerException ex) {
            mOrientation = 1;
        }
    } catch (IOException ex) {
        throw new IOException(String.format("E000 %s", mFile.getAbsolutePath()));
    }
}
Also used : GpsDirectory(com.drew.metadata.exif.GpsDirectory) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) IOException(java.io.IOException) MetadataException(com.drew.metadata.MetadataException)

Aggregations

MetadataException (com.drew.metadata.MetadataException)11 ExifIFD0Directory (com.drew.metadata.exif.ExifIFD0Directory)7 IOException (java.io.IOException)5 ImageProcessingException (com.drew.imaging.ImageProcessingException)4 Metadata (com.drew.metadata.Metadata)4 TikaException (org.apache.tika.exception.TikaException)4 ExifSubIFDDirectory (com.drew.metadata.exif.ExifSubIFDDirectory)2 BufferedImage (java.awt.image.BufferedImage)2 Date (java.util.Date)2 XMPMetadata (org.apache.jempbox.xmp.XMPMetadata)2 Metadata (org.apache.tika.metadata.Metadata)2 JpegProcessingException (com.drew.imaging.jpeg.JpegProcessingException)1 RiffProcessingException (com.drew.imaging.riff.RiffProcessingException)1 TiffProcessingException (com.drew.imaging.tiff.TiffProcessingException)1 ByteArrayReader (com.drew.lang.ByteArrayReader)1 Directory (com.drew.metadata.Directory)1 AviDirectory (com.drew.metadata.avi.AviDirectory)1 BmpHeaderDirectory (com.drew.metadata.bmp.BmpHeaderDirectory)1 EpsDirectory (com.drew.metadata.eps.EpsDirectory)1 ExifReader (com.drew.metadata.exif.ExifReader)1