我很难让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)))发布于 2011-03-10 21:13:44
对于任何阅读这篇文章的人,如果有同样的问题-在另一台机器上尝试一下。我两样都有
im = im.resize(size_tuple)和
im = im.transform(size_tuple, Image.EXTENT, (x1,y1,x2,y2)正确调整文件大小。我的服务器上的python安装肯定有什么问题。在我的本地机器上工作正常。
发布于 2014-04-22 06:30:10
下面是一个使用openCV和numpy在每个方向上调整图像大小的工作示例:
import cv2, numpy
original_image = cv2.imread('original_image.jpg',0)
original_height, original_width = original_image.shape[:2]
factor = 2
resized_image = cv2.resize(original_image, (int(original_height*factor), int(original_width*factor)), interpolation=cv2.INTER_CUBIC )
cv2.imwrite('resized_image.jpg',resized_image)
#fixed var name就这么简单。你想使用"cv2.INTER_CUBIC“来放大(因子> 1),使用"cv2.INTER_AREA”来缩小图像(因子< 1)。
https://stackoverflow.com/questions/5251010
复制相似问题