def _crop_image_vertically(img, target_height):
 (x, y) = img.size
 while (y > target_height):
  slice_height = min((y - target_height), 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 _crop_image_vertically ( img , target_height ) : ( x , y ) = img . size while ( y > target_height ) : slice_height = min ( ( y - target_height ) , 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
crop image vertically the the specified height .