def square_image(img):
 (x, y) = img.size
 while (y > x):
  slice_height = min((y - x), 10)
  bottom = img.crop((0, (y - slice_height), x, y))
  top = img.crop((0, 0, x, slice_height))
  if (image_entropy(bottom) < image_entropy(top)):
   img = img.crop((0, 0, x, (y - slice_height)))
  else:
   img = img.crop((0, slice_height, x, y))
  (x, y) = img.size
 return img

def square_image ( img ) : ( x , y ) = img . size while ( y > x ) : slice_height = min ( ( y - x ) , 10 ) bottom = img . crop ( ( 0 , ( y - slice_height ) , x , y ) ) top = img . crop ( ( 0 , 0 , x , slice_height ) ) if ( image_entropy ( bottom ) < image_entropy ( top ) ) : img = img . crop ( ( 0 , 0 , x , ( y - slice_height ) ) ) else : img = img . crop ( ( 0 , slice_height , x , y ) ) ( x , y ) = img . size return img
if the image is taller than it is wide .