def get_image_dimensions(file_or_path, close=False):
 from PIL import ImageFile as PillowImageFile
 p = PillowImageFile.Parser()
 if hasattr(file_or_path, 'read'):
  file = file_or_path
  file_pos = file.tell()
  file.seek(0)
 else:
  file = open(file_or_path, 'rb')
  close = True
 try:
  chunk_size = 1024
  while 1:
   data = file.read(chunk_size)
   if (not data):
    break
   try:
    p.feed(data)
   except zlib.error as e:
    if e.args[0].startswith('Error -5'):
     pass
    else:
     raise
   except struct.error:
    pass
   if p.image:
    return p.image.size
   chunk_size *= 2
  return (None, None)
 finally:
  if close:
   file.close()
  else:
   file.seek(file_pos)

def get_image_dimensions ( file_or_path , close = False ) : from PIL import ImageFile as PillowImageFile p = PillowImageFile . Parser ( ) if hasattr ( file_or_path , 'read' ) : file = file_or_path file_pos = file . tell ( ) file . seek ( 0 ) else : file = open ( file_or_path , 'rb' ) close = True try : chunk_size = 1024 while 1 : data = file . read ( chunk_size ) if ( not data ) : break try : p . feed ( data ) except zlib . error as e : if e . args [ 0 ] . startswith ( 'Error -5' ) : pass else : raise except struct . error : pass if p . image : return p . image . size chunk_size *= 2 return ( None , None ) finally : if close : file . close ( ) else : file . seek ( file_pos )
returns the of an image .