Python 使用django+;调整保存在S3上的图像的大小;django storages+;博托
尝试使用django+django storages+boto调整S3上的图像大小。下面是片段Python 使用django+;调整保存在S3上的图像的大小;django storages+;博托,python,django,amazon-s3,boto,Python,Django,Amazon S3,Boto,尝试使用django+django storages+boto调整S3上的图像大小。下面是片段 sbs = S3BotoStorage() # create a copy of the original image file_o = sbs.open(name, 'r') image_t = Image.open(file_o).copy() file_o.close() # resize the image image_t.thumbnail((500, 500), Image.ANTIA
sbs = S3BotoStorage()
# create a copy of the original image
file_o = sbs.open(name, 'r')
image_t = Image.open(file_o).copy()
file_o.close()
# resize the image
image_t.thumbnail((500, 500), Image.ANTIALIAS)
# overwrite or create new(changing name to name_new) the image
file_n = sbs.open(name, 'w')
image_t.save(file_n, 'JPEG')
image_t.close()
file_n.close()
这在使用django 1.7.4+django存储1.1.8+boto 2.36.0时运行良好。
但是在升级了django 1.9.2+django storages 1.4+boto 2.39.0后停止工作
不会抛出任何错误。代码执行得很好,但图像(name
)仍将是原始大小(1000*1000
,而不是500*500
)。即使我们将file\n
中的文件名更改为其他文件名(name\u new
),也不会创建新文件
同样的代码片段适用于文件系统存储
问题似乎出现在django存储1.4
中。没有解码太多,但是django 1.9.2+boto 2.39.0+django storages 1.1.8
工作正常。