If we know what kind of image we are facing, detecting the resolution is usually a matter of reading it from the image header.
For most image types, this is relatively simple, and as we can use imghdr to guess the right image type, we can then read the right part of the header, according to the detected type, to extract the size portion.