Need to glean image meta data for Java Web App - Need answer fast

I am supposed to scope how hard it would be to get the dimensions of an uploaded GIF in a Java-based web app. We are looking into using a third-party library. I first thought of ImageMagick, but someone mentioned that that might be a bit heavy-weight for our purposes. Can anyone suggest a free Java library that would be appropriate tor this task? I am supposed to give an estimate tomorrow.

Thanks for your help,
Rob

Based on this linkI think you can just read the ScreenWidth and ScreenHeight fields of the GIF header (bytes 6-7 and 8-9) as 16-bit shorts. (Based on looking at a GIF I happened to have in my “My pictures” folder, this is correct the width and height appear at those locations)

Can’t you just load the .gif into a java.awt.Image and call getHeight() and getWidth()?

How do you load a gif into a java.awt.Image? I don’t see a call in the API that will allow me to do that.

Thanks,
Rob

Nevermind. I found it in sun.awt.HeadlessToolkit.

Thanks,
Rob

I find the easiest way is to create a javax.swing.ImageIcon and then call getImage()

Other methods are complicated by the way images are loaded asynchronously to allow partial display of images which download slowly.

I notice that I need an ImageObserver to get the height and width. I am not sure what to do here. I tried getIconHeight() and it returned 0.

Thanks for your help,
Rob

The problem here is that, because images may be downloaded over potentially slow network connections, the loading of the data takes place in a separate thread. The ImageObserver interface allows a mechanism to monitor the progress but is a bit more complicated than one would wish. A common short cut is to ImageIcon which does all the work for you.

Try looking at this tutorial. It covers both methods and media tracker too (useful when dealing with several images simultaneously).

I found the problem. The path was not complete. Experimenting with the name resolved the issue.

Thanks for your help,
Rob