List of usage examples for javax.imageio.metadata IIOMetadata getMetadataFormatNames
public String[] getMetadataFormatNames()
From source file:de.mpg.imeji.presentation.metadata.extractors.BasicExtractor.java
public static List<String> extractTechMd(Item item) throws Exception { List<String> techMd = new ArrayList<String>(); URI uri = item.getFullImageUrl(); String imageUrl = uri.toURL().toString(); GetMethod method = new GetMethod(imageUrl); method.setFollowRedirects(false);// w ww .j a v a 2 s .c o m String userHandle = null; userHandle = LoginHelper.login(PropertyReader.getProperty("imeji.escidoc.user"), PropertyReader.getProperty("imeji.escidoc.password")); method.addRequestHeader("Cookie", "escidocCookie=" + userHandle); HttpClient client = new HttpClient(); client.executeMethod(method); InputStream input = method.getResponseBodyAsStream(); ImageInputStream iis = ImageIO.createImageInputStream(input); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); if (readers.hasNext()) { // pick the first available ImageReader ImageReader reader = readers.next(); // attach source to the reader reader.setInput(iis, true); // read metadata of first image IIOMetadata metadata = reader.getImageMetadata(0); String[] names = metadata.getMetadataFormatNames(); int length = names.length; for (int i = 0; i < length; i++) { displayMetadata(techMd, metadata.getAsTree(names[i])); } } return techMd; }
From source file:org.apache.tika.parser.image.ImageParser.java
private static void loadMetadata(IIOMetadata imageMetadata, Metadata metadata) { if (imageMetadata == null) { return;/* w ww .j a va2 s . co m*/ } String[] names = imageMetadata.getMetadataFormatNames(); if (names == null) { return; } for (String name : names) { loadNode(metadata, imageMetadata.getAsTree(name), "", false); } }
From source file:com.qwazr.extractor.parser.ImageParser.java
@Override public void parseContent(final MultivaluedMap<String, String> parameters, final Path path, final String extension, final String mimeType, final ParserResultBuilder resultBuilder) throws Exception { final ImagePHash imgPhash = new ImagePHash(); try (final ImageInputStream in = ImageIO.createImageInputStream(path.toFile())) { final Iterator<ImageReader> readers = ImageIO.getImageReaders(in); if (readers.hasNext()) { ParserFieldsBuilder result = resultBuilder.newDocument(); ImageReader reader = readers.next(); resultBuilder.metas().set(MIME_TYPE, "image/" + reader.getFormatName().toLowerCase()); try { reader.setInput(in);/*from w ww. ja va 2 s .c o m*/ result.add(WIDTH, reader.getWidth(0)); result.add(HEIGHT, reader.getHeight(0)); result.add(FORMAT, reader.getFormatName()); result.add(PHASH, imgPhash.getHash(reader.read(0))); IIOMetadata metadata = reader.getImageMetadata(0); if (metadata != null) { String[] names = metadata.getMetadataFormatNames(); if (names != null) for (String name : names) browseNodes("META", metadata.getAsTree(name), result); } } finally { reader.dispose(); } } } }
From source file:org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderImageIO.java
/** * Extract ICC Profile from ImageIO Metadata. This method currently only * supports PNG and JPEG metadata.//w w w .java 2 s . c o m * * @param iiometa * The ImageIO Metadata * @return an ICC Profile or null. */ private ICC_Profile tryToExctractICCProfile(IIOMetadata iiometa) { ICC_Profile iccProf = null; String supportedFormats[] = iiometa.getMetadataFormatNames(); for (int i = 0; i < supportedFormats.length; i++) { String format = supportedFormats[i]; Element root = (Element) iiometa.getAsTree(format); if (PNG_METADATA_NODE.equals(format)) { iccProf = this.tryToExctractICCProfileFromPNGMetadataNode(root); } else if (JPEG_METADATA_NODE.equals(format)) { iccProf = this.tryToExctractICCProfileFromJPEGMetadataNode(root); } } return iccProf; }
From source file:net.algart.simagis.imageio.IIOMetadataToJsonConverter.java
public final JSONObject toJson(IIOMetadata metadata) throws JSONException { if (metadata == null) throw new NullPointerException("Null metadata"); JSONObject result = new JSONObject(); JSONArray formats = new JSONArray(); final String[] formatNames = metadata.getMetadataFormatNames(); if (formatNames != null) { for (String formatName : formatNames) { final Node tree = metadata.getAsTree(formatName); JSONObject format = new JSONObject(); format.put("formatName", formatName); format.put("tree", treeToJson(tree)); formats.put(format);/*from w w w . ja v a 2 s.c o m*/ } } result.put("formats", formats); return result; }
From source file:lucee.runtime.img.Image.java
public IIOMetadata getMetaData(Struct parent) { InputStream is = null;//from ww w .j a v a 2 s . c o m javax.imageio.stream.ImageInputStreamImpl iis = null; try { if (source instanceof File) { iis = new FileImageInputStream((File) source); } else if (source == null) iis = new MemoryCacheImageInputStream(new ByteArrayInputStream(getImageBytes(format, true))); else iis = new MemoryCacheImageInputStream(is = source.getInputStream()); Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); if (readers.hasNext()) { // pick the first available ImageReader ImageReader reader = readers.next(); IIOMetadata meta = null; synchronized (sync) { // attach source to the reader reader.setInput(iis, true); // read metadata of first image meta = reader.getImageMetadata(0); meta.setFromTree(FORMAT, meta.getAsTree(FORMAT)); reader.reset(); } // generating dump if (parent != null) { String[] formatNames = meta.getMetadataFormatNames(); for (int i = 0; i < formatNames.length; i++) { Node root = meta.getAsTree(formatNames[i]); //print.out(XMLCaster.toString(root)); addMetaddata(parent, "metadata", root); } } return meta; } } catch (Throwable t) { } finally { ImageUtil.closeEL(iis); IOUtil.closeEL(is); } return null; }