Coding Challenge: Fast Width/Height of an Image
I am trying to find out the width and height of an image (a URL) transferring as few bytes as possible. This coding challenge has two separate parts:
- Finding the cheapest way to retrieve width and height.
- Verifying that the solution is indeed cheap.
The first part is not that interesting since it’s a fairly well documented problem. A bit too documented, actually, since I found several solutions:
- A naïve version using ImageIO.
- A more advanced solution using ImageReaders.
- A hand rolled solution written by Jaimon Matthew.
This last solution looks pretty efficient from a network perspective but I’m worried it might leave out a few corner cases in image handling. The first two solutions are probably battle tested and very robust but I have no idea how effective they are from a network standpoint (their Javadoc doesn’t describe the specifics of how they operate).
So… Do you have a better solution? And whether you do or don’t, how would you assess how many bytes these implementations transfer?
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)