gpt4 book ai didi

python - PIL : enlarge an image

转载 作者:太空狗 更新时间:2023-10-29 21:17:52 24 4
gpt4 key购买 nike

我无法让 PIL 放大图像。大图像可以正常缩小,但小图像不会变大。

# get the ratio of the change in height of this image using the
# by dividing the height of the first image
s = h / float(image.size[1])
# calculate the change in dimension of the new image
new_size = tuple([int(x*s) for x in image.size])
# if this image height is larger than the image we are sizing to
if image.size[1] > h:
# make a thumbnail of the image using the new image size
image.thumbnail(new_size)
by = "thumbnailed"
# add the image to the images list
new_images.append(image)
else:
# otherwise try to blow up the image - doesn't work
new_image = image.resize(new_size)
new_images.append(new_image)
by = "resized"
logging.debug("image %s from: %s to %s" % (by, str(image.size), str(new_size)))

最佳答案

resizetransform 方法都能正确调整图像大小。

size_tuple = im.size
x1 = y1 = 0
x2, y2 = size_tuple

# resize
im = im.resize(size_tuple)

# transform
im = im.transform(size_tuple, Image.EXTENT, (x1,y1,x2,y2))

如果您遇到与我描述的相同的问题 - 请在另一台机器上尝试。我服务器上的python安装肯定有问题。它在我的本地机器上运行良好。

关于python - PIL : enlarge an image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5251010/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com