an be InputStream or RandomAccessFile ii.setDetermineImageNumber(true); // default is false ii.setCollectComments(true); // default is false if (!ii.check()) { System.err.println("Not a supported image file format."); return; } System.out.println(ii.getFormatName() + ", " + ii.getMimeType() + ", " + ii.getWidth() + " x " + ii.getHeight() + " pixels, " + ii.getBitsPerPixel() + " bits per pixel, " + ii.getNumberOfImages() + " image(s), " + ii.getNumberOfComments() + " comment(s)."); // there are other properties, check out the API documentation You can also use this class as a command line program. Call it with a number of image file names and URLs as parameters:
java ImageInfo *.jpg *.png *.gif http://somesite.tld/image.jpg
or call it without parameters and pipe data to it:
java ImageInfo < image.jpg
Known limitations:
- When the determination of the number of images is turned off, GIF bits per pixel are only read from the global header. For some GIFs, local palettes change this to a typically larger value. To be certain to get the correct color depth, call setDetermineImageNumber(true) before calling check(). The complete scan over the GIF file will take additional time.
- Transparency information is not included in the bits per pixel count. Actually, it was my decision not to include those bits, so it's a feature! ;-)
Requirements:
The latest version can be found at http://www.geocities.com/marcoschmidt.geo/image-info.html.
Written by Marco Schmidt.
This class is contributed to the Public Domain. Use it at your own risk.
Last modification 2004-02-29.
History:
- 2001-08-24 Initial version.
- 2001-10-13 Added support for the file formats BMP and PCX.
- 2001-10-16 Fixed bug in read(int[], int, int) that returned
- 2002-01-22 Added support for file formats Amiga IFF and Sun Raster (RAS).
- 2002-01-24 Added support for file formats Portable Bitmap / Graymap / Pixmap (PBM, PGM, PPM) and Adobe Photoshop (PSD). Added new method getMimeType() to return the MIME type associated with a particular file format.
- 2002-03-15 Added support to recognize number of images in file. Only works with GIF. Use {@link #setDetermineImageNumber} with
true
as argument to identify animated GIFs( {@link #getNumberOfImages()} will return a value larger than 1
). - 2002-04-10 Fixed a bug in the feature 'determine number of images in animated GIF' introduced with version 1.1. Thanks to Marcelo P. Lima for sending in the bug report. Released as 1.1.1.
- 2002-04-18 Added {@link #setCollectComments(boolean)}. That new method lets the user specify whether textual comments are to be stored in an internal list when encountered in an input image file / stream. Added two methods to return the physical width and height of the image in dpi: {@link #getPhysicalWidthDpi()} and {@link #getPhysicalHeightDpi()}. If the physical resolution could not be retrieved, these methods return
-1
. - 2002-04-23 Added support for the new properties physical resolution and comments for some formats. Released as 1.2.
- 2002-06-17 Added support for SWF, sent in by Michael Aird. Changed checkJpeg() so that other APP markers than APP0 will not lead to a failure anymore. Released as 1.3.
- 2003-07-28 Bug fix - skip method now takes return values into consideration. Less bytes than necessary may have been skipped, leading to flaws in the retrieved information in some cases. Thanks to Bernard Bernstein for pointing that out. Released as 1.4.
- 2004-02-29 Added support for recognizing progressive JPEG and interlaced PNG and GIF. A new method {@link #isProgressive()} returns whether ImageInfohas found that the storage type is progressive (or interlaced). Thanks to Joe Germuska for suggesting the feature. Bug fix: BMP physical resolution is now correctly determined. Released as 1.5.