0
我有以下功能,它会拍摄一张图像,然后以三种尺寸返回。另一个功能是将这些图像上传到Amazon S3。在我看来,似乎有一些冗余的文件如何保存 -在PIL中调整图像大小
def resize_image(image, size_as_tuple):
"""
Example usage: resize_image(image, (100,200))
"""
image_as_string=""
for c in image.chunks():
image_as_string += c
imagefile = cStringIO.StringIO(image_as_string)
image = Image.open(imagefile)
if image.mode not in ("L", "RBG"):
image = image.convert("RGB")
filename = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(14)) + ".jpg"
height, width = size_as_tuple[0], size_as_tuple[1]
image.thumbnail((height, width), Image.ANTIALIAS)
imagefile = open(os.path.join('/tmp', filename), 'w')
image.save(imagefile, 'JPEG')
imagefile = open(os.path.join('/tmp', filename), 'r')
content = File(imagefile)
return (filename, content)
有没有办法改善这种情况?
谢谢你的提示! – David542