I think we can try to read the jpeg header information without using these big libraries. The gallery needs to do more things than us, and that's why they need all of it. But I think we don't need so many things.

https://web.archive.org/web/20130305080105/http://www.64lines.com/jpeg-width-height could be used as documentation for example?