Refine search
public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log) { if (metadata.hasErrors()) { log.print(file); log.print('\n'); for (Directory directory : metadata.getDirectories()) { if (!directory.hasErrors()) continue; for (String error : directory.getErrors()) { log.printf("\t[%s] %s\n", directory.getName(), error); _errorCount++; } } } }
String fileName = file.getName(); String urlName = StringUtil.urlEncode(filePath); ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); String make = exifIFD0Directory == null ? "" : exifIFD0Directory.getString(ExifIFD0Directory.TAG_MAKE); String model = exifIFD0Directory == null ? "" : exifIFD0Directory.getString(ExifIFD0Directory.TAG_MODEL); for (Directory directory : metadata.getDirectories()) { String directoryName = directory.getName(); for (Tag tag : directory.getTags()) { String tagName = tag.getTagName(); String description = tag.getDescription(); for (String error : directory.getErrors()) System.err.println("ERROR: " + error);
Metadata metadata = new Metadata(); for (JpegSegmentType segmentType : exifReader.getSegmentTypes()) { exifReader.readJpegSegments(segmentData.getSegments(segmentType), metadata, segmentType); Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); if (directory != null) { for (Tag tag : directory.getTags()) { if (tag.getTagType() == ExifDirectoryBase.TAG_DATETIME) { dateTime = tag.getDescription();
protected void addError(@NotNull String errorMessage, final @NotNull Metadata metadata) { ErrorDirectory directory = metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (directory == null) { metadata.addDirectory(new ErrorDirectory(errorMessage)); } else { directory.addError(errorMessage); } } }
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); : "Yes"; for (Directory directory : metadata.getDirectories()) { if (directory.getClass().getName().contains("Makernote")) { makernote = directory.getName().replace("Makernote", "").trim(); break;
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; } }
try { InputStream is = new URL("your image url").openStream(); BufferedInputStream bis = new BufferedInputStream(is); Metadata metadata = ImageMetadataReader.readMetadata(bis,true); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { System.out.println(tag); } } } catch (ImageProcessingException e){} catch (IOException e) {}
_metadata.addDirectory(printIMDirectory); processPrintIM(printIMDirectory, tagOffset, reader, byteCount); return true; PanasonicRawWbInfoDirectory dirWbInfo = new PanasonicRawWbInfoDirectory(); dirWbInfo.setParent(_currentDirectory); _metadata.addDirectory(dirWbInfo); processBinary(dirWbInfo, tagOffset, reader, byteCount, false, 2); return true; PanasonicRawWbInfo2Directory dirWbInfo2 = new PanasonicRawWbInfo2Directory(); dirWbInfo2.setParent(_currentDirectory); _metadata.addDirectory(dirWbInfo2); processBinary(dirWbInfo2, tagOffset, reader, byteCount, false, 3); return true; PanasonicRawDistortionDirectory dirDistort = new PanasonicRawDistortionDirectory(); dirDistort.setParent(_currentDirectory); _metadata.addDirectory(dirDistort); processBinary(dirDistort, tagOffset, reader, byteCount, true, 1); return true; try { Metadata jpegDirectory = JpegMetadataReader.readMetadata(jpegmem); for (Directory directory : jpegDirectory.getDirectories()) { directory.setParent(_currentDirectory); _metadata.addDirectory(directory);
Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); JpegDirectory jpegDirectory = metadata.getFirstDirectoryOfType(JpegDirectory.class); orientation = directory.getInt(ExifIFD0Directory.TAG_ORIENTATION); } catch (MetadataException me) { logger.warn("Could not get orientation");
@Nullable public static Geolocation getGeolocation(@Nullable final byte[] imageBytes) throws ImageProcessingException, IOException { if (imageBytes != null && imageBytes.length > 0) { final Metadata metadata = ImageMetadataReader.readMetadata(new BufferedInputStream(new ByteArrayInputStream(imageBytes)), false); if (metadata != null) { final GpsDirectory gpsDirectory = metadata.getDirectory(GpsDirectory.class); if (gpsDirectory != null) { return new GeolocationImpl(gpsDirectory); } } } return null; }
/** * Copies extracted tags to tika metadata using registered handlers. * * @param metadataExtractor Tag directories from a Metadata Extractor "reader" * @throws MetadataException This method does not handle exceptions from Metadata Extractor */ protected void handle(com.drew.metadata.Metadata metadataExtractor) throws MetadataException { handle(metadataExtractor.getDirectories().iterator()); }
private static void writeHierarchyLevel(@NotNull Metadata metadata, @NotNull PrintWriter writer, @Nullable Directory parent, int level) { final int indent = 4; for (Directory child : metadata.getDirectories()) { if (parent == null) { if (child.getParent() != null) continue; } else if (!parent.equals(child.getParent())) { continue; } for (int i = 0; i < level*indent; i++) { writer.write(' '); } writer.write("- "); writer.write(child.getName()); writer.write(NEW_LINE); writeHierarchyLevel(metadata, writer, child, level + 1); } }
@NotNull private Directory getCurrentOrErrorDirectory() { if (_currentDirectory != null) return _currentDirectory; ErrorDirectory error = _metadata.getFirstDirectoryOfType(ErrorDirectory.class); if (error != null) return error; pushDirectory(ErrorDirectory.class); return _currentDirectory; }
Directory ifd0Directory = _metadata.getFirstDirectoryOfType(ExifIFD0Directory.class); String cameraMake = ifd0Directory == null ? null : ifd0Directory.getString(ExifIFD0Directory.TAG_MAKE); break; default: _currentDirectory.addError("Unsupported Nikon makernote data ignored."); break; reader.setMotorolaByteOrder(firstSevenChars.equals("KDK INFO")); KodakMakernoteDirectory directory = new KodakMakernoteDirectory(); _metadata.addDirectory(directory); processKodakMakernote(directory, makernoteOffset, reader); } else if ("Canon".equalsIgnoreCase(cameraMake)) { } else if (reader.getUInt16(makernoteOffset) == ReconyxHyperFireMakernoteDirectory.MAKERNOTE_VERSION) { ReconyxHyperFireMakernoteDirectory directory = new ReconyxHyperFireMakernoteDirectory(); _metadata.addDirectory(directory); processReconyxHyperFireMakernote(directory, makernoteOffset, reader); } else if (firstNineChars.equalsIgnoreCase("RECONYXUF")) { ReconyxUltraFireMakernoteDirectory directory = new ReconyxUltraFireMakernoteDirectory(); _metadata.addDirectory(directory); processReconyxUltraFireMakernote(directory, makernoteOffset, reader); } else if ("SAMSUNG".equals(cameraMake)) {
/** * Indicates whether any errors were reported during the reading of metadata values. * This value will be true if Directory.hasErrors() is true for one of the contained {@link Directory} objects. * * @return whether one of the contained directories has an error */ public boolean hasErrors() { for (Directory directory : getDirectories()) { if (directory.hasErrors()) return true; } return false; }
@NotNull public static Metadata readMetadata(@NotNull InputStream inputStream, @Nullable Iterable<JpegSegmentMetadataReader> readers) throws JpegProcessingException, IOException { Metadata metadata = new Metadata(); process(metadata, inputStream, readers); return metadata; }
/*************************************************************************** * * **************************************************************************/ private static Directory getEXIFDirectory (final Node node) { if (node.getNodeName().equals("unknown")) { if (Integer.parseInt(node.getAttributes().getNamedItem("MarkerTag").getNodeValue()) == EXIF) { final byte[] data = (byte[])((IIOMetadataNode)node).getUserObject(); final Metadata metadata = new Metadata(); new ExifReader().extract(data, metadata); return metadata.getDirectory(ExifSubIFDDirectory.class); } } Node child = node.getFirstChild(); while (child != null) { final Directory directory = getEXIFDirectory(child); if (directory != null) { return directory; } child = child.getNextSibling(); } return null; }
/** * Tries to read the orientation data from the given image {@link Metadata}. Returns <code>null</code> if not * found or if an error occurs. */ @Nullable public static ImageOrientation getOrientation(@Nullable final Metadata metadata) { if (metadata != null) { final Directory exifIfd0Directory = metadata.getDirectory(ExifIFD0Directory.class); if (exifIfd0Directory != null) { try { return findById(exifIfd0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION)); } catch (Exception e) { LOG.info("ImageOrientation.getOrientation(): Exception while trying to read the orientation data from the EXIF. Ignoring and just returning null"); } } } return null; }
public HeifHandler(Metadata metadata) { this.metadata = metadata; this.directory = getDirectory(); metadata.addDirectory(directory); }
public void extract(@NotNull SequentialReader reader, @NotNull Metadata metadata) { Directory directory = new AdobeJpegDirectory(); metadata.addDirectory(directory); try { reader.setMotorolaByteOrder(false); if (!reader.getString(PREAMBLE.length()).equals(PREAMBLE)) { directory.addError("Invalid Adobe JPEG data header."); return; } directory.setInt(AdobeJpegDirectory.TAG_DCT_ENCODE_VERSION, reader.getUInt16()); directory.setInt(AdobeJpegDirectory.TAG_APP14_FLAGS0, reader.getUInt16()); directory.setInt(AdobeJpegDirectory.TAG_APP14_FLAGS1, reader.getUInt16()); directory.setInt(AdobeJpegDirectory.TAG_COLOR_TRANSFORM, reader.getInt8()); } catch (IOException ex) { directory.addError("IO exception processing data: " + ex.getMessage()); } } }