I\'m looking for a fast way to get the height and width of an image in pixels. It should handle at least JPG, PNG and TIFF, but the more the better. I emphasize
It's the pixel dimensions you want (width and height), I assume?
I'd think that most file formats have some header info defining the dimensions, so that the software reading the file can know how much room it must reserve before starting to read the file. Some "raw" type file formats might just be a stream of bytes with some "end of line" byte at the end of each horizontal row of pixels (in which case the software must read the first line and divide the size of the byte stream by the line length to get the height).
I don't think you can make this in any "generic" way, as you need to understand the file format (or use a library of course) in order to know how to read it. You can probably find some code that will in most cases give a rough estimate of the dimensions without reading the whole file, but I think some filetypes may require you to read the whole file to be sure what dimensions it really have. I expect that most web centric image formats have a header with such info so that the browser can create the box dimensions before the whole image is loaded.
I'd guess a good library would have some methods to get the dimensions of the files it handles, and that those methods would be implemented as efficient as possible.
Update: imageinfo seems like it does what you want. (Have not tested it)