While it's possible to call open(filename, 'rb')
and check through the binary image headers for the dimensions, it seems much more useful to install PIL and spend your time writing great new software! You gain greater file format support and the reliability that comes from widespread usage. From the PIL documentation, it appears that the code you would need to complete your task would be:
from PIL import Image
im = Image.open('filename.png')
print 'width: %d - height: %d' % im.size # returns (width, height) tuple
As for writing code yourself, I'm not aware of a module in the Python standard library that will do what you want. You'll have to open()
the image in binary mode and start decoding it yourself. You can read about the formats at: