Python / Pillow: Como dimensionar uma imagem
Suponha que eu tenha uma imagem com 2322px x 4128px. Como o dimensiono para que a largura e a altura sejam menores que 1028 px?
Não poderei usarImage.resize
(https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.resize), pois isso exige que eu forneça a nova largura e altura. O que pretendo fazer é (pseudo-código abaixo):
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)
Acho que preciso usarImage.thumbnail
, mas de acordo com este exemplo (http://pillow.readthedocs.org/en/latest/reference/Image.html#create-thumbnails) e esta resposta (Como redimensiono uma imagem usando PIL e mantenho sua proporção?), a largura e a altura são fornecidas para criar a miniatura. Existe alguma função que pega a nova largura ou a nova altura (não as duas) e escala a imagem inteira?