Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageIO - get image type and exif data

Given some source file (or more generic - input stream), I need to find out

  • is it an image
  • if it is an image, then retrieve its type (png/jpeg/gif/etc)
  • retrieve exif data, if available

I looked at the API, but it is not clear how to get the type of image or Exif data.

like image 559
jdevelop Avatar asked Jul 03 '12 11:07

jdevelop


People also ask

What image types have EXIF data?

The exchangeable image file format (EXIF) is a standard for embedding technical metadata in image files that many camera manufacturers use and many image-processing programs support. EXIF metadata can be embedded in TIFF and JPEG images.

How do I get EXIF data from a photo?

On a Windows PC using File Explorer right-click on the file you want to see the data for. You will see a window pop up with various options. Click on Properties and then on Details. This will bring up the EXIF data for that photo.

Can ImageIO read JPG?

Just use the read method of the Java ImageIO class, and you can open/read images in a variety of formats (GIF, JPG, PNG) in basically one line of Java code.

How do I view EXIF data on a JPEG?

All you have to right-click on the preferred image in Windows File Explorer and select the Properties option. In the properties dialogue box, click on the Details tab. After that, you will view EXIF data information like size, resolution, and other additional details of the image.


2 Answers

Last time I had to do this, a couple of years ago, the standard API couldn't read EXIF data. This library can do so though:

http://www.drewnoakes.com/code/exif/

like image 166
OpenSauce Avatar answered Oct 01 '22 04:10

OpenSauce


Easy answer: Use https://github.com/drewnoakes/metadata-extractor/

If you're crazy/brave/curious, you could get image type from the stream by reading the first few bytes (these are magic numbers). I believe the exif is generally at the start of the stream too.

like image 33
matt burns Avatar answered Oct 01 '22 05:10

matt burns