Read all image metadata with Java

How to read all the metadata of an image (image format, width and height) in Java. We will the use the awesome metadata-extractor library.

1) Add the dependency

Add the following dependency to your pom.xml:


2) Read the image metadata

For this example, we will use an image from our own website,, but you can replace it with any other image that you load as a Java InputStream:

import com.drew.imaging.ImageMetadataReader;
import com.drew.metadata.*;

String image = "";
URL url = new URL(image);
InputStream in = new BufferedInputStream(url.openStream());
Metadata metadata = ImageMetadataReader.readMetadata(in);

for (Directory d : metadata.getDirectories()) {
    for (Tag tag : d.getTags())


In the console, you will get the following information:

PNG-IHDR Directory (7 tags)
[PNG-IHDR] Image Width - 700
[PNG-IHDR] Image Height - 413
[PNG-IHDR] Bits Per Sample - 8
[PNG-IHDR] Color Type - Indexed Color
[PNG-IHDR] Compression Type - Deflate
[PNG-IHDR] Filter Method - Adaptive
[PNG-IHDR] Interlace Method - No Interlace

PNG-gAMA Directory (1 tag)
[PNG-gAMA] Image Gamma - 0.455

PNG-sRGB Directory (1 tag)
[PNG-sRGB] sRGB Rendering Intent - Perceptual

PNG-PLTE Directory (1 tag)
[PNG-PLTE] Palette Size - 256

File Type Directory (4 tags)
[File Type] Detected File Type Name - PNG
[File Type] Detected File Type Long Name - Portable Network Graphics
[File Type] Detected MIME Type - image/png
[File Type] Expected File Name Extension - png

So we can see that our image’s format is PNG, the image width is 700 and the image height is 413.

That’s it for this tutorial ! Please leave a reply below if you have questions.

Leave a Reply

Your email address will not be published. Required fields are marked *