def image_shape(img):
 if hasattr(img, 'shape'):
  return (img.shape[1], img.shape[0])
 return (img.width, img.height)

def image_shape ( img ) : if hasattr ( img , 'shape' ) : return ( img . shape [ 1 ] , img . shape [ 0 ] ) return ( img . width , img . height )
handle different image formats .