假设我有一张图片大小为2322px x 4128px。如何缩放它以使宽度和高度都小于1028px?
由于使用Image.resize
需要提供新的宽度和高度,所以无法使用该方法。我的计划是(以下是伪代码):
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)
我猜我需要使用Image.thumbnail
,但是根据这个例子和这个答案,创建缩略图需要提供宽度和高度。是否有任何函数可以只取新的宽度或新的高度(而不是两者),并缩放整个图像?
Image.thumbnail
存在什么问题?你想用自己的代码实现这个功能。 - famousgarkin