Java Code Examples for com.drew.metadata.Metadata#getDirectories()
The following examples show how to use
com.drew.metadata.Metadata#getDirectories() .
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: ExtractImageMetadata.java From localization_nifi with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 6 votes |
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); } }
Example 3
Source File: ImageResource.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
protected Map<String, String> getImgMetadata(File file, List<String> ignoreKeysList) { logger.debug("Get image Metadata in Resource Action"); Map<String, String> meta = new HashMap<>(); try { Metadata metadata = ImageMetadataReader.readMetadata(file); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { if (!ignoreKeysList.contains(tag.getTagName())) { logger.debug("Add Metadata with key: {}", tag.getTagName()); meta.put(tag.getTagName(), tag.getDescription()); } else { logger.debug("Skip Metadata key {}", tag.getTagName()); } } } } catch (ImageProcessingException|IOException ex) { logger.error("Error reading image metadata for file {}", file.getName(), ex); } return meta; }
Example 4
Source File: ExtractImageMetadata.java From nifi with Apache License 2.0 | 6 votes |
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; }
Example 5
Source File: MetadataHelper.java From leafpicrevived with GNU General Public License v3.0 | 5 votes |
public MediaDetailsMap<String, String> getAllDetails(Context context, Media media) { MediaDetailsMap<String, String> data = new MediaDetailsMap<String, String>(); try { Metadata metadata = ImageMetadataReader.readMetadata(context.getContentResolver().openInputStream(media.getUri())); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { data.put(tag.getTagName(), directory.getObject(tag.getTagType()) + ""); } } } catch (Exception e) { e.printStackTrace(); } return data; }
Example 6
Source File: ImageDataReader.java From java-11-examples with Apache License 2.0 | 5 votes |
public static ImageInfo getImageInfo(InputStream imageStream) throws ImageProcessingException, IOException { Metadata metadata = ImageMetadataReader.readMetadata(imageStream); ImageInfo.Builder builder = new ImageInfo.Builder(); for (Directory directory: metadata.getDirectories()) { for (Tag tag: directory.getTags()) { if (ParsingUtils.IMAGE_HEIGHT.equals(tag.getTagName())) { builder.setPixelsY(ParsingUtils.getIntegerFromData(tag.getDescription())); } else if (ParsingUtils.IMAGE_WIDTH.equals(tag.getTagName())) { builder.setPixelsX(ParsingUtils.getIntegerFromData(tag.getDescription())); } } } return builder.build(); }
Example 7
Source File: SampleProcessor.java From tutorials with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void process(Record record, SingleLaneBatchMaker batchMaker) throws StageException { LOG.info("Input record: {}", record); FileRef fileRef = record.get("/fileRef").getValueAsFileRef(); Metadata metadata; try { metadata = ImageMetadataReader.readMetadata(fileRef.createInputStream(getContext(), InputStream.class)); } catch (ImageProcessingException | IOException e) { String filename = record.get("/fileInfo/filename").getValueAsString(); LOG.info("Exception getting metadata from {}", filename, e); throw new OnRecordErrorException(record, Errors.SAMPLE_02, e); } for (Directory directory : metadata.getDirectories()) { LinkedHashMap<String, Field> listMap = new LinkedHashMap<>(); for (Tag tag : directory.getTags()) { listMap.put(tag.getTagName(), Field.create(tag.getDescription())); } if (directory.hasErrors()) { for (String error : directory.getErrors()) { LOG.info("ERROR: {}", error); } } record.set("/" + directory.getName(), Field.createListMap(listMap)); } LOG.info("Output record: {}", record); batchMaker.addRecord(record); }
Example 8
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 5 votes |
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++; } } } }
Example 9
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 5 votes |
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 10
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 5 votes |
@Override public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log) { super.onExtractionSuccess(file, metadata, relativePath, log); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { // Only interested in unknown tags (those without names) if (tag.hasTagName()) continue; HashMap<Integer, Integer> occurrenceCountByTag = _occurrenceCountByTagByDirectory.get(directory.getName()); if (occurrenceCountByTag == null) { occurrenceCountByTag = new HashMap<Integer, Integer>(); _occurrenceCountByTagByDirectory.put(directory.getName(), occurrenceCountByTag); } Integer count = occurrenceCountByTag.get(tag.getTagType()); if (count == null) { count = 0; occurrenceCountByTag.put(tag.getTagType(), 0); } occurrenceCountByTag.put(tag.getTagType(), count + 1); } } }
Example 11
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 5 votes |
@Override public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log) { super.onExtractionSuccess(file, metadata, relativePath, log); // Iterate through all values, calling toString to flush out any formatting exceptions for (Directory directory : metadata.getDirectories()) { directory.getName(); for (Tag tag : directory.getTags()) { tag.getTagName(); tag.getDescription(); } } }
Example 12
Source File: ResourceAction.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
protected Map getImgMetadata(File file) { logger.debug("Get image Metadata in Resource Action"); Map<String, String> meta = new HashMap<>(); ResourceInterface resourcePrototype = this.getResourceManager().createResourceType(this.getResourceType()); try { Metadata metadata = ImageMetadataReader.readMetadata(file); String ignoreKeysConf = resourcePrototype.getMetadataIgnoreKeys(); String[] ignoreKeys = null; if (null != ignoreKeysConf) { ignoreKeys = ignoreKeysConf.split(","); logger.debug("Metadata ignoreKeys: {}", ignoreKeys); } else { logger.debug("Metadata ignoreKeys not configured"); } List<String> ignoreKeysList = new ArrayList<String>(); if (null != ignoreKeys) { ignoreKeysList = Arrays.asList(ignoreKeys); } for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { if (!ignoreKeysList.contains(tag.getTagName())) { logger.debug("Add Metadata with key: {}", tag.getTagName()); meta.put(tag.getTagName(), tag.getDescription()); } else { logger.debug("Skip Metadata key {}", tag.getTagName()); } } } } catch (ImageProcessingException ex) { logger.error("Error reading metadata from file " + this.getFileName() + " - message " + ex.getMessage()); } catch (IOException ioex) { logger.error("Error reading file", ioex); } return meta; }
Example 13
Source File: LoadedImage.java From edslite with GNU General Public License v2.0 | 4 votes |
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 14
Source File: MetaDataTreeTableModel.java From Pixelitor with GNU General Public License v3.0 | 4 votes |
public MetaDataTreeTableModel(Metadata metadata) { super(new Object()); for (Directory directory : metadata.getDirectories()) { dirNodes.add(new DirNode(directory)); } }