def image_resize_and_sharpen(image, size, preserve_aspect_ratio=False, factor=2.0):
 if (image.mode != 'RGBA'):
  image = image.convert('RGBA')
 image.thumbnail(size, Image.ANTIALIAS)
 if preserve_aspect_ratio:
  size = image.size
 sharpener = ImageEnhance.Sharpness(image)
 resized_image = sharpener.enhance(factor)
 image = Image.new('RGBA', size, (255, 255, 255, 0))
 image.paste(resized_image, (((size[0] - resized_image.size[0]) / 2), ((size[1] - resized_image.size[1]) / 2)))
 return image

def image_resize_and_sharpen ( image , size , preserve_aspect_ratio = False , factor = 2.0 ) : if ( image . mode != 'RGBA' ) : image = image . convert ( 'RGBA' ) image . thumbnail ( size , Image . ANTIALIAS ) if preserve_aspect_ratio : size = image . size sharpener = ImageEnhance . Sharpness ( image ) resized_image = sharpener . enhance ( factor ) image = Image . new ( 'RGBA' , size , ( 255 , 255 , 255 , 0 ) ) image . paste ( resized_image , ( ( ( size [ 0 ] - resized_image . size [ 0 ] ) / 2 ) , ( ( size [ 1 ] - resized_image . size [ 1 ] ) / 2 ) ) ) return image
create a thumbnail by resizing while keeping ratio .