handle different image formats, returning (width,height) tuple

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