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));
}
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;
}
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());
}
}
}
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);
}
}
Aggregations