com.drew.metadata.MetadataException Java Examples

The following examples show how to use com.drew.metadata.MetadataException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImgUtilsTest.java    From TranskribusCore with GNU General Public License v3.0 6 votes vote down vote up
public void testExiftoolVsImageIO() throws FileNotFoundException, IOException, TimeoutException, InterruptedException, ImageProcessingException, MetadataException {
//		File imgFile = new File("/mnt/dea_scratch/TRP/test/I._ZvS_1902_4.Q/ZS-I-1902-198 (1).jpg");
		File imgFile = new File("/tmp/Exif_orientation_test/Exif_orientation_test/IMG_20181115_144511.jpg");
		SSW sw = new SSW();
		sw.start();
		Dimension dim = ImgUtils.readImageDimensionsWithExiftool(imgFile);
		long exiftoolTime = sw.stop(true, "exiftool: ");
		sw.start();
		Dimension dim2 = TrpImageIO.readImageDimensions(imgFile);
		long imageioTime = sw.stop(true, "imageio: ");
		sw.start();
		Dimension dim3 = ImgUtils.readImageDimensionsWithMdParser(imgFile);
		long mdExtractorTime = sw.stop(true, "md-extractor: ");
		
		logger.info("exiftool: " + dim.getWidth() + " x " + dim.getHeight() + " -> " + exiftoolTime + " ms");
		logger.info("imageio: " + dim2.getWidth() + " x " + dim2.getHeight() + " -> " + imageioTime + " ms");
		logger.info("md-extractor: " + dim3.getWidth() + " x " + dim3.getHeight() + " -> " + mdExtractorTime + " ms");
	}
 
Example #2
Source File: MutableImage.java    From react-native-camera-face-detector with MIT License 6 votes vote down vote up
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);
    }
}
 
Example #3
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setPixelHeight(Directory directory, int tagType) {
  try {
    setPixelHeight(directory.getInt(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #4
Source File: JpegDescriptorTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetComponentDescription() throws MetadataException
{
    JpegComponent component1 = new JpegComponent(1, 0x22, 0);
    _directory.setObject(TAG_COMPONENT_DATA_1, component1);
    assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", _directory.getDescription(TAG_COMPONENT_DATA_1));
    assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", _descriptor.getComponentDataDescription(0));
}
 
Example #5
Source File: ExifDirectoryTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testDateTime() throws JpegProcessingException, IOException, MetadataException
{
    Metadata metadata = ExifReaderTest.processBytes("Tests/Data/nikonMakernoteType2a.jpg.app1");

    ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
    ExifSubIFDDirectory exifSubIFDDirectory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);

    assertNotNull(exifIFD0Directory);
    assertNotNull(exifSubIFDDirectory);

    assertEquals("2003:10:15 10:37:08", exifIFD0Directory.getString(ExifIFD0Directory.TAG_DATETIME));
    assertEquals("80", exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME));
    assertEquals("2003:10:15 10:37:08", exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL));
    assertEquals("80", exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME_ORIGINAL));
    assertEquals("2003:10:15 10:37:08", exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED));
    assertEquals("80", exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME_DIGITIZED));

    assertEquals(1066214228800L, exifIFD0Directory.getDate(
        ExifIFD0Directory.TAG_DATETIME,
        exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME),
        null
    ).getTime());
    assertEquals(1066210628800L, exifIFD0Directory.getDate(
        ExifIFD0Directory.TAG_DATETIME,
        exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME),
        TimeZone.getTimeZone("GMT+0100")
    ).getTime());

    assertEquals(1066214228800L, exifSubIFDDirectory.getDateModified().getTime());
    assertEquals(1066210628800L, exifSubIFDDirectory.getDateModified(TimeZone.getTimeZone("GMT+0100")).getTime());
    assertEquals(1066214228800L, exifSubIFDDirectory.getDateOriginal().getTime());
    assertEquals(1066210628800L, exifSubIFDDirectory.getDateOriginal(TimeZone.getTimeZone("GMT+0100")).getTime());
    assertEquals(1066214228800L, exifSubIFDDirectory.getDateDigitized().getTime());
    assertEquals(1066210628800L, exifSubIFDDirectory.getDateDigitized(TimeZone.getTimeZone("GMT+0100")).getTime());
}
 
Example #6
Source File: ExifDirectoryTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolution() throws JpegProcessingException, IOException, MetadataException
{
    Metadata metadata = ExifReaderTest.processBytes("Tests/Data/withUncompressedRGBThumbnail.jpg.app1");

    ExifThumbnailDirectory thumbnailDirectory = metadata.getFirstDirectoryOfType(ExifThumbnailDirectory.class);
    assertNotNull(thumbnailDirectory);
    assertEquals(72, thumbnailDirectory.getInt(ExifThumbnailDirectory.TAG_X_RESOLUTION));

    ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
    assertNotNull(exifIFD0Directory);
    assertEquals(216, exifIFD0Directory.getInt(ExifIFD0Directory.TAG_X_RESOLUTION));
}
 
Example #7
Source File: ExifDirectoryTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testGeoLocation() throws IOException, MetadataException
{
    Metadata metadata = ExifReaderTest.processBytes("Tests/Data/withExifAndIptc.jpg.app1.0");

    GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);
    assertNotNull(gpsDirectory);
    GeoLocation geoLocation = gpsDirectory.getGeoLocation();
    assertEquals(54.989666666666665, geoLocation.getLatitude(), 0.001);
    assertEquals(-1.9141666666666666, geoLocation.getLongitude(), 0.001);
}
 
Example #8
Source File: AppleRunTimeMakernoteDescriptor.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Nullable
private String calculateTimeInSeconds()
{
    try {
        long value = _directory.getLong(AppleRunTimeMakernoteDirectory.CMTimeValue);
        long scale = _directory.getLong(AppleRunTimeMakernoteDirectory.CMTimeScale);

        return String.format("%d seconds", (value / scale));
    } catch (MetadataException ignored) {
        return null;
    }
}
 
Example #9
Source File: AppleRunTimeMakernoteDescriptor.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Nullable
private String flagsDescription()
{
    try {
        final int value = _directory.getInt(AppleRunTimeMakernoteDirectory.CMTimeFlags);

        StringBuilder sb = new StringBuilder();

        if ((value & 0x1) == 1)
            sb.append("Valid");
        else
            sb.append("Invalid");

        if ((value & 0x2) != 0)
            sb.append(", rounded");

        if ((value & 0x4) != 0)
            sb.append(", positive infinity");

        if ((value & 0x8) != 0)
            sb.append(", negative infinity");

        if ((value & 0x10) != 0)
            sb.append(", indefinite");

        return sb.toString();
    } catch (MetadataException ignored) {
        return null;
    }
}
 
Example #10
Source File: ExifDirectoryTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testGpsDate() throws IOException, MetadataException
{
    Metadata metadata = ExifReaderTest.processBytes("Tests/Data/withPanasonicFaces.jpg.app1");

    GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);
    assertNotNull(gpsDirectory);
    assertEquals("2010:06:24", gpsDirectory.getString(GpsDirectory.TAG_DATE_STAMP));
    assertEquals("10/1 17/1 21/1", gpsDirectory.getString(GpsDirectory.TAG_TIME_STAMP));
    assertEquals(1277374641000L, gpsDirectory.getGpsDate().getTime());
}
 
Example #11
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setPixelWidth(Directory directory, int tagType) {
  try {
    setPixelWidth(directory.getInt(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #12
Source File: ImgUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public static Dimension readImageDimensionsWithMdParser(URL url) throws FileNotFoundException, IOException {
	try {
		ImageTransformation imgDim = TrpImgMdParser.readImageDimension(url);
		return new Dimension(imgDim.getDestinationWidth(), imgDim.getDestinationHeight());
	} catch(ImageProcessingException | MetadataException e) {
		logger.warn("Metadata extractor did not find EXIF data. Falling back to reading raw image data dimension.");
		return TrpImageIO.readImageDimensions(url);
	}
}
 
Example #13
Source File: ImgUtils.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public static Dimension readImageDimensionsWithMdParser(File imgFile) throws FileNotFoundException, IOException {
	try {
		ImageTransformation imgDim = TrpImgMdParser.readImageDimension(imgFile);
		return new Dimension(imgDim.getDestinationWidth(), imgDim.getDestinationHeight());
	} catch(ImageProcessingException | MetadataException e) {
		logger.warn("Metadata extractor did not find EXIF data. Falling back to reading raw image data dimension.");
		return TrpImageIO.readImageDimensions(imgFile);
	}
}
 
Example #14
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setAudioSampleRate(Directory directory, int tagType) {
  try {
    setAudioSampleRate(directory.getDouble(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #15
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setAudioSampleSize(Directory directory, int tagType) {
  try {
    setAudioSampleSize(directory.getInt(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #16
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setFrameRate(Directory directory, int tagType) {
  try {
    setFrameRate(directory.getDouble(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #17
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setAlpha(Directory directory, int tagType) {
  try {
    setAlpha(directory.getBoolean(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #18
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setBitPerPixel(Directory directory, int tagType1, int tagType2) {
  try {
    setBitPerPixel(directory.getInt(tagType1) * directory.getInt(tagType2));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #19
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setBitPerPixel(Directory directory, int tagType) {
  try {
    setBitPerPixel(directory.getInt(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #20
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setDPIHeight(Directory directory, int tagType, double factor) {
  try {
    setDPIHeight(directory.getInt(tagType) * factor);
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #21
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setDPIHeight(Directory directory, int tagType) {
  try {
    setDPIHeight(directory.getInt(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #22
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setDPIWidth(Directory directory, int tagType, double factor) {
  try {
    setDPIWidth(directory.getInt(tagType) * factor);
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #23
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setDPIWidth(Directory directory, int tagType) {
  try {
    setDPIWidth(directory.getInt(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #24
Source File: GenericMetadataDirectory.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void setOrientation(Directory directory, int tagType) {
  try {
    setOrientation(directory.getInt(tagType));
  } catch (MetadataException e) {
    // Nothing needs to be done
  }
}
 
Example #25
Source File: NikonType2MakernoteTest1.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetHueAdjustmentDescription() throws MetadataException
{
    assertEquals("0 degrees", _descriptor.getDescription(NikonType2MakernoteDirectory.TAG_CAMERA_HUE_ADJUSTMENT));
    assertEquals("0 degrees", _descriptor.getHueAdjustmentDescription());
}
 
Example #26
Source File: NikonType2MakernoteTest1.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetLensDescription() throws MetadataException
{
    assertEquals("24-85mm f/3.5-4.5", _descriptor.getDescription(NikonType2MakernoteDirectory.TAG_LENS));
    assertEquals("24-85mm f/3.5-4.5", _descriptor.getLensDescription());
}
 
Example #27
Source File: ExifHelper.java    From sejda with GNU Affero General Public License v3.0 4 votes vote down vote up
private static int readExifOrientation(Metadata metadata) throws MetadataException {
    Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
    return directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
}
 
Example #28
Source File: JfifDirectory.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
public int getResX() throws MetadataException
{
    return getInt(JfifDirectory.TAG_RESX);
}
 
Example #29
Source File: JfifDirectory.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link #getResX} instead.
 */
@Deprecated
public int getImageHeight() throws MetadataException
{
    return getInt(JfifDirectory.TAG_RESX);
}
 
Example #30
Source File: JfifDirectory.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
public int getResY() throws MetadataException
{
    return getInt(JfifDirectory.TAG_RESY);
}