Java Code Examples for com.drew.metadata.MetadataException

The following examples show how to use com.drew.metadata.MetadataException. These examples are extracted from open source projects. 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 Project: react-native-camera-face-detector   Source File: MutableImage.java    License: 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 2
Source Project: TranskribusCore   Source File: ImgUtilsTest.java    License: 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 3
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 4
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 5
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 6
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 7
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 8
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 9
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 10
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 11
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 12
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 13
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 14
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 15
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: 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 16
Source Project: TranskribusCore   Source File: ImgUtils.java    License: 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 17
Source Project: TranskribusCore   Source File: ImgUtils.java    License: 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 18
@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 19
@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 20
Source Project: metadata-extractor   Source File: JpegDescriptorTest.java    License: 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 21
Source Project: metadata-extractor   Source File: ExifDirectoryTest.java    License: 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 22
Source Project: metadata-extractor   Source File: ExifDirectoryTest.java    License: 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 23
Source Project: metadata-extractor   Source File: ExifDirectoryTest.java    License: 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 24
Source Project: metadata-extractor   Source File: ExifDirectoryTest.java    License: 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 25
Source Project: metadata-extractor   Source File: HuffmanTablesDirectory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @return The number of Huffman tables held by this {@link HuffmanTablesDirectory} instance.
 */
public int getNumberOfTables() throws MetadataException
{
    return getInt(HuffmanTablesDirectory.TAG_NUMBER_OF_TABLES);
}
 
Example 26
Source Project: metadata-extractor   Source File: JpegDirectory.java    License: Apache License 2.0 4 votes vote down vote up
public int getImageWidth() throws MetadataException
{
    return getInt(JpegDirectory.TAG_IMAGE_WIDTH);
}
 
Example 27
Source Project: metadata-extractor   Source File: JpegDirectory.java    License: Apache License 2.0 4 votes vote down vote up
public int getImageHeight() throws MetadataException
{
    return getInt(JpegDirectory.TAG_IMAGE_HEIGHT);
}
 
Example 28
Source Project: metadata-extractor   Source File: JpegDirectory.java    License: Apache License 2.0 4 votes vote down vote up
public int getNumberOfComponents() throws MetadataException
{
    return getInt(JpegDirectory.TAG_NUMBER_OF_COMPONENTS);
}
 
Example 29
Source Project: metadata-extractor   Source File: JfxxDirectory.java    License: Apache License 2.0 4 votes vote down vote up
public int getExtensionCode() throws MetadataException
{
    return getInt(JfxxDirectory.TAG_EXTENSION_CODE);
}
 
Example 30
Source Project: metadata-extractor   Source File: JfifDirectory.java    License: Apache License 2.0 4 votes vote down vote up
public int getVersion() throws MetadataException
{
    return getInt(JfifDirectory.TAG_VERSION);
}