#NEWLINE# def get_image_dimensions( file_or_path ) : #NEWLINE# #INDENT# 'Returns the (width, height) of an image, given an open file or a path.' #NEWLINE# from PIL import ImageFile as PILImageFile #NEWLINE# p = PILImageFile . Parser ( ) #NEWLINE# if hasattr ( file_or_path , 'read' ) : #NEWLINE# #INDENT# file = file_or_path #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# file = open ( file_or_path , 'rb' ) #NEWLINE# #UNINDENT# while 1 : #NEWLINE# #INDENT# data = file . read ( 1024 ) #NEWLINE# if ( not data ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# p . feed ( data ) #NEWLINE# if p . image : #NEWLINE# #INDENT# return p . image . size #NEWLINE# #UNINDENT# #UNINDENT# return None