Reading image metadata in Java is now possible thanks to Apache Tika support in JDeli. With the new release of JDeli 2023.03 which includes two plugins for Apache Tika.
You can download JDeli here to try for yourself.
Image metadata extraction
Using JDeli, you can read image metadata from a range of different formats.
We currently support the following:
- BMP
- GIF
- HEIC/HEIF
- JPEG
- JPX/JP2
- PNG
- TIFF
- WebP
To get started, we pass a TikaInputStream, along with a ContentHandler and Metadata objects, to the MetadataParser.
TikaInputStream tik = TikaInputStream.get(Paths.get("file.img")); MetadataParser parser = new MetadataParser(); ToXMLContentHandler xmlH = new ToXMLContentHandler(); Metadata metadata = new Metadata(); parser.parse(tik, xmlH, metadata, null);
The result is stored in the content handler as an HTML table where each column is a metadata attribute.
More information about image metadata extraction available on our support site.
Image format detection
Using an ImageDetector, you can detect an image’s MIME Type:
ImageDetector detector = new ImageDetector(); MediaType mimeType = detector.detect(TikaInputStream.get(Paths.get("file.img")), null);
You can then do MediaType.getSubtype() to find out the image format.
More information about image format detection available on our support site.
Download JDeli
Get started today with our free JDeli trial, which has no Email requirement.
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(dicomImageFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(heicImageFile);
// Write an image
JDeli.write(bufferedImage, "heic", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpegImageFile);
// Write an image
JDeli.write(bufferedImage, "jpeg", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpeg2000ImageFile);
// Write an image
JDeli.write(bufferedImage, "jpx", outputStreamOrFile);
// Write an image
JDeli.write(bufferedImage, "pdf", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(pngImageFile);
// Write an image
JDeli.write(bufferedImage, "png", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(tiffImageFile);
// Write an image
JDeli.write(bufferedImage, "tiff", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(webpImageFile);
// Write an image
JDeli.write(bufferedImage, "webp", outputStreamOrFile);
Why do developers choose JDeli over free alternatives?
- Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP
- Better support than alternatives for JPEG, PNG, TIFF.
- Prevent JVM crashes caused by native code in other image libraries
- Better performance than other popular Java image libraries