Python / Pillow: Cómo escalar una imagen
Supongamos que tengo una imagen que es 2322px x 4128px. ¿Cómo lo escalo para que tanto el ancho como la altura sean inferiores a 1028 px?
No podré usarImage.resize
(https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.resize) ya que eso me exige dar el ancho y la altura nuevos. Lo que planeo hacer es (pseudo código a continuación):
if (image.width or image.height) > 1028:
if image.width > image.height:
tn_image = image.scale(make width of image 1028)
# since the height is less than the width and I am scaling the image
# and making the width less than 1028px, the height will surely be
# less than 1028px
else: #image's height is greater than it's width
tn_image = image.scale(make height of image 1028)
Supongo que necesito usarImage.thumbnail
, pero de acuerdo con este ejemplo (http://pillow.readthedocs.org/en/latest/reference/Image.html#create-thumbnails) y esta respuesta (¿Cómo cambio el tamaño de una imagen usando PIL y mantengo su relación de aspecto?), tanto el ancho como el alto se proporcionan para crear la miniatura. ¿Hay alguna función que tome el nuevo ancho o la nueva altura (no ambos) y escale toda la imagen?