code: def _getImageSize(filename):
      
      result = None
      file = open(filename, 'rb')
      if file.read(8) == b'\x89PNG\r\n\x1a\n': # PNG
          while 1:
              length, = _struct.unpack('>i', file.read(4))
              chunkID = file.read(4)
              if chunkID == '': # EOF
                  break
              if chunkID == b'IHDR':
                  # return width, height
                  result = _struct.unpack('>ii', file.read(8))
                  break
              file.seek(4 + length, 1)
          file.close()
          return result
      file.seek(0)
      if file.read(8) == b'BM': # Bitmap
          file.seek(18, 0) # skip to size data
          result = _struct.unpack('<ii', file.read(8))
      file.close()
      return result
docs: Try to get the width and height of a bmp of png image file