I'm not familiar with any ready-made libraries or classes to do it in PHP without a subprocess call, but if you can't find one, writing your own would definitely be the way to go.
PNG's a fairly simple block stream format, so seeking to a specific block and extracting some header fields is trivial.
All you'd need is something which reads and checks the 8-byte 89 50 4E 47 0D 0A 1A 0A
PNG header and then alternates between reading 8 bytes (chunk length plus type) and seeking past the block using the length until you hit the chunk type you want.
For the geometry, assuming the PNG follows the spec, here's how it'd go:
- Read and verify PNG header (8 bytes)
- Read and check header of first block (8 bytes)
- Success.
type = IHDR
- Read additional 8 bytes for geometry (width, height. 4 bytes each)
- If the other field you wanted isn't in IHDR, use the chunk size from step 2 to seek to the next block in search of the other field you wanted.
It'd probably take me 5 to 15 minutes to whip something like that up in Python. (I've done similar things with RAR and GIF) Maybe 15 to 25 in PHP since I've got less experience doing low-level file I/O in it.