Search in sources :

Example 1 with Tag

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

the class ImageMetadataExtractorTest method testCopyUnknownFieldsHandler.

@Test
public void testCopyUnknownFieldsHandler() throws MetadataException {
    Directory d = mock(Directory.class);
    Tag t1 = mock(Tag.class);
    when(t1.getTagName()).thenReturn("Image Description");
    when(t1.getDescription()).thenReturn("t1");
    Tag t2 = mock(Tag.class);
    when(t2.getTagName()).thenReturn(Metadata.KEYWORDS);
    when(t2.getDescription()).thenReturn("known");
    Tag t3 = mock(Tag.class);
    when(t3.getTagName()).thenReturn(TikaCoreProperties.DESCRIPTION.getName());
    when(t3.getDescription()).thenReturn("known");
    List<Tag> tags = Arrays.asList(t1, t2, t3);
    when(d.getTags()).thenReturn(tags);
    Metadata metadata = new Metadata();
    new ImageMetadataExtractor.CopyUnknownFieldsHandler().handle(d, metadata);
    assertEquals("t1", metadata.get("Image Description"));
    assertNull("keywords should be excluded from bulk copy because it is a defined field", metadata.get(Metadata.KEYWORDS));
    assertNull(metadata.get(TikaCoreProperties.DESCRIPTION));
}
Also used : Metadata(org.apache.tika.metadata.Metadata) Tag(com.drew.metadata.Tag) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) Directory(com.drew.metadata.Directory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) JpegCommentDirectory(com.drew.metadata.jpeg.JpegCommentDirectory) Test(org.junit.Test)

Example 2 with Tag

use of com.drew.metadata.Tag in project nifi by apache.

the class ExtractImageMetadata method getTags.

private Map<String, String> getTags(Integer max, Metadata metadata) {
    Map<String, String> results = new HashMap<>();
    int i = 0;
    for (Directory directory : metadata.getDirectories()) {
        for (Tag tag : directory.getTags()) {
            results.put(directory.getName() + "." + tag.getTagName(), tag.getDescription());
            if (max != null) {
                i++;
                if (i >= max) {
                    return results;
                }
            }
        }
    }
    return results;
}
Also used : HashMap(java.util.HashMap) Tag(com.drew.metadata.Tag) Directory(com.drew.metadata.Directory)

Example 3 with Tag

use of com.drew.metadata.Tag in project Lucee by lucee.

the class ImageMetaDrew method fill.

private static void fill(Struct info, Metadata metadata) {
    Iterator<Directory> directories = metadata.getDirectories().iterator();
    while (directories.hasNext()) {
        Directory directory = directories.next();
        Struct sct = new StructImpl();
        info.setEL(KeyImpl.init(directory.getName()), sct);
        Iterator<Tag> tags = directory.getTags().iterator();
        while (tags.hasNext()) {
            Tag tag = tags.next();
            sct.setEL(KeyImpl.init(tag.getTagName()), tag.getDescription());
        }
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Tag(com.drew.metadata.Tag) Directory(com.drew.metadata.Directory) Struct(lucee.runtime.type.Struct)

Example 4 with Tag

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

the class MutableImage method writeDataToFile.

public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
    fos.close();
    try {
        ExifInterface exif = new ExifInterface(file.getAbsolutePath());
        // copy original exif data to the output exif...
        for (Directory directory : originalImageMetaData().getDirectories()) {
            for (Tag tag : directory.getTags()) {
                int tagType = tag.getTagType();
                Object object = directory.getObject(tagType);
                exif.setAttribute(tag.getTagName(), object.toString());
            }
        }
        // Add missing exif data from a sub directory
        ExifSubIFDDirectory directory = originalImageMetaData().getFirstDirectoryOfType(ExifSubIFDDirectory.class);
        for (Tag tag : directory.getTags()) {
            int tagType = tag.getTagType();
            // As some of exif data does not follow naming of the ExifInterface the names need
            // to be transformed into Upper camel case format.
            String tagName = tag.getTagName().replaceAll(" ", "");
            Object object = directory.getObject(tagType);
            if (tagName.equals(ExifInterface.TAG_EXPOSURE_TIME)) {
                exif.setAttribute(tagName, convertExposureTimeToDoubleFormat(object.toString()));
            } else {
                exif.setAttribute(tagName, object.toString());
            }
        }
        writeLocationExifData(options, exif);
        if (hasBeenReoriented)
            rewriteOrientation(exif);
        exif.saveAttributes();
    } catch (ImageProcessingException | IOException e) {
        Log.e(TAG, "failed to save exif data", e);
    }
}
Also used : ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) ImageProcessingException(com.drew.imaging.ImageProcessingException) FileOutputStream(java.io.FileOutputStream) ExifInterface(android.media.ExifInterface) Tag(com.drew.metadata.Tag) IOException(java.io.IOException) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) Directory(com.drew.metadata.Directory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory)

Aggregations

Directory (com.drew.metadata.Directory)4 Tag (com.drew.metadata.Tag)4 ExifIFD0Directory (com.drew.metadata.exif.ExifIFD0Directory)2 ExifSubIFDDirectory (com.drew.metadata.exif.ExifSubIFDDirectory)2 ExifInterface (android.media.ExifInterface)1 ImageProcessingException (com.drew.imaging.ImageProcessingException)1 JpegCommentDirectory (com.drew.metadata.jpeg.JpegCommentDirectory)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 Metadata (org.apache.tika.metadata.Metadata)1 Test (org.junit.Test)1