com.drew.metadata.exif.ExifSubIFDDirectory Java Examples

The following examples show how to use com.drew.metadata.exif.ExifSubIFDDirectory. 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: DirectoryTest.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetNonExistentTagIsNullForAllTypes() throws Exception
{
    assertNull(_directory.getString(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getInteger(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getDoubleObject(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getFloatObject(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getByteArray(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getDate(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getIntArray(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getLongObject(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getObject(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getRational(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getRationalArray(ExifSubIFDDirectory.TAG_APERTURE));
    assertNull(_directory.getStringArray(ExifSubIFDDirectory.TAG_APERTURE));
}
 
Example #2
Source File: MetadataTest.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderOfSameType()
{
    Metadata metadata = new Metadata();
    Directory directory2 = new ExifSubIFDDirectory();
    Directory directory3 = new ExifSubIFDDirectory();
    Directory directory1 = new ExifSubIFDDirectory();

    metadata.addDirectory(directory1);
    metadata.addDirectory(directory2);
    metadata.addDirectory(directory3);

    Collection<ExifSubIFDDirectory> directories = metadata.getDirectoriesOfType(ExifSubIFDDirectory.class);

    assertNotNull(directories);
    assertEquals(3, directories.size());
    assertSame(directory1, directories.toArray()[0]);
    assertSame(directory2, directories.toArray()[1]);
    assertSame(directory3, directories.toArray()[2]);
}
 
Example #3
Source File: MetadataTest.java    From metadata-extractor with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderOfDifferentTypes()
{
    Metadata metadata = new Metadata();
    Directory directory1 = new ExifSubIFDDirectory();
    Directory directory2 = new ExifThumbnailDirectory();
    Directory directory3 = new ExifIFD0Directory();

    metadata.addDirectory(directory1);
    metadata.addDirectory(directory2);
    metadata.addDirectory(directory3);

    List<Directory> directories = new ArrayList<Directory>();
    for (Directory directory : metadata.getDirectories()) {
        directories.add(directory);
    }

    assertEquals(3, directories.size());
    assertSame(directory1, directories.toArray()[0]);
    assertSame(directory2, directories.toArray()[1]);
    assertSame(directory3, directories.toArray()[2]);
}
 
Example #4
Source File: ImageRecordReader.java    From Bats with Apache License 2.0 5 votes vote down vote up
private boolean isVersionTag(final Directory directory, final int tagType) {
  return directory instanceof ExifSubIFDDirectory &&
      (tagType == ExifSubIFDDirectory.TAG_EXIF_VERSION || tagType == ExifSubIFDDirectory.TAG_FLASHPIX_VERSION) ||
      directory instanceof ExifInteropDirectory &&
      tagType == ExifInteropDirectory.TAG_INTEROP_VERSION ||
      directory instanceof FujifilmMakernoteDirectory &&
      tagType == FujifilmMakernoteDirectory.TAG_MAKERNOTE_VERSION ||
      directory instanceof NikonType2MakernoteDirectory &&
      tagType == NikonType2MakernoteDirectory.TAG_FIRMWARE_VERSION ||
      directory instanceof OlympusCameraSettingsMakernoteDirectory &&
      tagType == OlympusCameraSettingsMakernoteDirectory.TagCameraSettingsVersion ||
      directory instanceof OlympusEquipmentMakernoteDirectory &&
      tagType == OlympusEquipmentMakernoteDirectory.TAG_EQUIPMENT_VERSION ||
      directory instanceof OlympusFocusInfoMakernoteDirectory &&
      tagType == OlympusFocusInfoMakernoteDirectory.TagFocusInfoVersion ||
      directory instanceof OlympusImageProcessingMakernoteDirectory &&
      tagType == OlympusImageProcessingMakernoteDirectory.TagImageProcessingVersion ||
      directory instanceof OlympusMakernoteDirectory &&
      tagType == OlympusMakernoteDirectory.TAG_MAKERNOTE_VERSION ||
      directory instanceof OlympusRawDevelopment2MakernoteDirectory &&
      tagType == OlympusRawDevelopment2MakernoteDirectory.TagRawDevVersion ||
      directory instanceof OlympusRawDevelopmentMakernoteDirectory &&
      tagType == OlympusRawDevelopmentMakernoteDirectory.TagRawDevVersion ||
      directory instanceof OlympusRawInfoMakernoteDirectory &&
      tagType == OlympusRawInfoMakernoteDirectory.TagRawInfoVersion ||
      directory instanceof PanasonicMakernoteDirectory &&
      (tagType == PanasonicMakernoteDirectory.TAG_FIRMWARE_VERSION || tagType == PanasonicMakernoteDirectory.TAG_MAKERNOTE_VERSION || tagType == PanasonicMakernoteDirectory.TAG_EXIF_VERSION) ||
      directory instanceof SamsungType2MakernoteDirectory &&
      tagType == SamsungType2MakernoteDirectory.TagMakerNoteVersion ||
      directory instanceof SonyType6MakernoteDirectory &&
      tagType == SonyType6MakernoteDirectory.TAG_MAKERNOTE_THUMB_VERSION ||
      directory instanceof PanasonicRawIFD0Directory &&
      tagType == PanasonicRawIFD0Directory.TagPanasonicRawVersion;
}
 
Example #5
Source File: CreateFilePane.java    From pattypan with MIT License 5 votes vote down vote up
/**
 *
 * @param filePath
 * @return
 */
private String getExifDate(File file) {

  try {
    Metadata metadata = ImageMetadataReader.readMetadata(file);
    Directory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
    int dateTag = ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL;

    if (directory != null && directory.containsTag(dateTag)) {
      Date date = directory.getDate(dateTag, TimeZone.getDefault());
      return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
    } else {
      return "";
    }
  } catch (ImageProcessingException | IOException ex) {
    Session.LOGGER.log(Level.INFO, 
        "Exif error for {0}: {1}",
        new String[]{file.getName(), ex.getLocalizedMessage()}
    );
    return "";
  }
}
 
Example #6
Source File: EXIFMetadataExtractor.java    From cineast with MIT License 5 votes vote down vote up
/**
 * Extracts the metadata from the specified path and returns a List of
 * MediaObjectMetadataDescriptor objects (one for each metadata entry).
 *
 * @param objectId ID of the multimedia object for which metadata will be generated.
 * @param path Path to the file for which metadata should be extracted.
 * @return List of MultimediaMetadataDescriptors. The list may be empty but must always be
 * returned!
 */
@Override
public List<MediaObjectMetadataDescriptor> extract(String objectId, Path path) {
  ExifSubIFDDirectory md = MetadataUtil
      .getMetadataDirectoryOfType(path, ExifSubIFDDirectory.class);
  if (md == null) {
    return Collections.emptyList();
  }
  Set<Entry<String, Object>> set = Maps.transformValues(FIELDS, md::getObject).entrySet();
  return set.stream().filter(e -> e.getValue() != null).map(
      e -> MediaObjectMetadataDescriptor.of(objectId, this.domain(), e.getKey(), e.getValue()))
      .filter(e -> ! (e.getValueProvider() instanceof NothingProvider))
      .collect(Collectors.toList());
}
 
Example #7
Source File: ProcessAllImagesInFolderUtility.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
Row(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath)
{
    this.file = file;
    this.metadata = metadata;
    this.relativePath = relativePath;

    ExifIFD0Directory ifd0Dir = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
    ExifSubIFDDirectory subIfdDir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
    ExifThumbnailDirectory thumbDir = metadata.getFirstDirectoryOfType(ExifThumbnailDirectory.class);
    if (ifd0Dir != null) {
        manufacturer = ifd0Dir.getDescription(ExifIFD0Directory.TAG_MAKE);
        model = ifd0Dir.getDescription(ExifIFD0Directory.TAG_MODEL);
    }
    boolean hasMakernoteData = false;
    if (subIfdDir != null) {
        exifVersion = subIfdDir.getDescription(ExifSubIFDDirectory.TAG_EXIF_VERSION);
        hasMakernoteData = subIfdDir.containsTag(ExifSubIFDDirectory.TAG_MAKERNOTE);
    }
    if (thumbDir != null) {
        Integer width = thumbDir.getInteger(ExifThumbnailDirectory.TAG_IMAGE_WIDTH);
        Integer height = thumbDir.getInteger(ExifThumbnailDirectory.TAG_IMAGE_HEIGHT);
        thumbnail = width != null && height != null
            ? String.format("Yes (%s x %s)", width, height)
            : "Yes";
    }
    for (Directory directory : metadata.getDirectories()) {
        if (directory.getClass().getName().contains("Makernote")) {
            makernote = directory.getName().replace("Makernote", "").trim();
            break;
        }
    }
    if (makernote == null) {
        makernote = hasMakernoteData ? "(Unknown)" : "N/A";
    }
}
 
Example #8
Source File: JpegMetadataReaderTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
private void validate(Metadata metadata)
{
    Directory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
    assertNotNull(directory);
    assertEquals("80", directory.getString(ExifSubIFDDirectory.TAG_ISO_EQUIVALENT));
    directory = metadata.getFirstDirectoryOfType(HuffmanTablesDirectory.class);
    assertNotNull(directory);
    assertTrue(((HuffmanTablesDirectory) directory).isOptimized());
}
 
Example #9
Source File: DirectoryTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test public void testSetAndGetMultipleTagsInSingleDirectory() throws Exception
{
    _directory.setString(ExifSubIFDDirectory.TAG_APERTURE, "TAG_APERTURE");
    _directory.setString(ExifSubIFDDirectory.TAG_BATTERY_LEVEL, "TAG_BATTERY_LEVEL");
    assertEquals("TAG_APERTURE", _directory.getString(ExifSubIFDDirectory.TAG_APERTURE));
    assertEquals("TAG_BATTERY_LEVEL", _directory.getString(ExifSubIFDDirectory.TAG_BATTERY_LEVEL));
}
 
Example #10
Source File: DirectoryTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsTag() throws Exception
{
    assertFalse(_directory.containsTag(ExifSubIFDDirectory.TAG_APERTURE));
    _directory.setString(ExifSubIFDDirectory.TAG_APERTURE, "Tag Value");
    assertTrue(_directory.containsTag(ExifSubIFDDirectory.TAG_APERTURE));
}
 
Example #11
Source File: MetadataTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testHasErrors() throws Exception
{
    ExifSubIFDDirectory directory = new ExifSubIFDDirectory();
    directory.addError("Test Error 1");

    Metadata metadata = new Metadata();
    assertFalse(metadata.hasErrors());

    metadata.addDirectory(directory);
    assertTrue(metadata.hasErrors());
}
 
Example #12
Source File: MetadataTest.java    From metadata-extractor with Apache License 2.0 5 votes vote down vote up
@Test
public void testToString()
{
    Metadata metadata = new Metadata();
    assertEquals("Metadata (0 directories)", metadata.toString());

    metadata.addDirectory(new ExifIFD0Directory());
    assertEquals("Metadata (1 directory)", metadata.toString());

    metadata.addDirectory(new ExifSubIFDDirectory());
    assertEquals("Metadata (2 directories)", metadata.toString());
}
 
Example #13
Source File: ImageRecordReader.java    From Bats with Apache License 2.0 4 votes vote down vote up
private void processDirectory(final MapWriter writer, final Directory directory, final Metadata metadata) {
  for (Tag tag : directory.getTags()) {
    try {
      final int tagType = tag.getTagType();
      Object value;
      if (descriptive || isDescriptionTag(directory, tagType)) {
        value = directory.getDescription(tagType);
        if (directory instanceof PngDirectory) {
          if (((PngDirectory) directory).getPngChunkType().areMultipleAllowed()) {
            value = new String[] { (String) value };
          }
        }
      } else {
        value = directory.getObject(tagType);
        if (directory instanceof ExifIFD0Directory && tagType == ExifIFD0Directory.TAG_DATETIME) {
          ExifSubIFDDirectory exifSubIFDDir = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
          String subsecond = null;
          if (exifSubIFDDir != null) {
            subsecond = exifSubIFDDir.getString(ExifSubIFDDirectory.TAG_SUBSECOND_TIME);
          }
          value = directory.getDate(tagType, subsecond, timeZone);
        } else if (directory instanceof ExifSubIFDDirectory) {
          if (tagType == ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL) {
            value = ((ExifSubIFDDirectory) directory).getDateOriginal(timeZone);
          } else if (tagType == ExifSubIFDDirectory.TAG_DATETIME_DIGITIZED) {
            value = ((ExifSubIFDDirectory) directory).getDateDigitized(timeZone);
          }
        } else if (directory instanceof GpsDirectory) {
          if (tagType == GpsDirectory.TAG_LATITUDE) {
            value = ((GpsDirectory) directory).getGeoLocation().getLatitude();
          } else if (tagType == GpsDirectory.TAG_LONGITUDE) {
            value = ((GpsDirectory) directory).getGeoLocation().getLongitude();
          }
        }
        if (isVersionTag(directory, tagType)) {
          value = directory.getString(tagType, "US-ASCII");
        } else if (isDateTag(directory, tagType)) {
          value = directory.getDate(tagType, timeZone);
        }
      }
      writeValue(writer, formatName(tag.getTagName()), value);
    } catch (Exception e) {
      // simply skip this tag
    }
  }
}
 
Example #14
Source File: LoadedImage.java    From edslite with GNU General Public License v2.0 4 votes vote down vote up
private void loadInitOrientation(Path imagePath)
{
    try
    {
        InputStream s = imagePath.getFile().getInputStream();
        try
        {
            Metadata m = ImageMetadataReader.readMetadata(s);

            for(Directory directory: m.getDirectories())
                if(directory.containsTag(ExifSubIFDDirectory.TAG_ORIENTATION))
                {
                    int orientation = directory.getInt(ExifSubIFDDirectory.TAG_ORIENTATION);
                    switch (orientation)
                    {
                        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_180:
                            _rotation = 180;
                            break;
                        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                            _rotation = 180;
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_TRANSPOSE:
                            _rotation = 90;
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_90:
                            _rotation = 90;
                            break;
                        case ExifInterface.ORIENTATION_TRANSVERSE:
                            _rotation = -90;
                            _flipX = true;
                            break;
                        case ExifInterface.ORIENTATION_ROTATE_270:
                            _rotation = -90;
                            break;
                    }
                    break;
                }
        }
        finally
        {
            s.close();
        }
    }
    catch (Exception e)
    {
        if(GlobalConfig.isDebug())
            Logger.log(e);
    }
}
 
Example #15
Source File: DirectoryTest.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Test public void testSetSameTagMultipleTimesOverwritesValue() throws Exception
{
    _directory.setInt(ExifSubIFDDirectory.TAG_APERTURE, 1);
    _directory.setInt(ExifSubIFDDirectory.TAG_APERTURE, 2);
    assertEquals(2, _directory.getInt(ExifSubIFDDirectory.TAG_APERTURE));
}
 
Example #16
Source File: MetadataTest.java    From metadata-extractor with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetDirectoryWhenNotExists()
{
    assertNull(new Metadata().getFirstDirectoryOfType(ExifSubIFDDirectory.class));
}