我是Django的新手,最近我写了一个有关图像表示的项目。
在我看来,我有一个功能可以显示图像。但是我首先从加密/解密服务中下载了映像。这意味着下载的图像为纯数据字节格式。
现在,我想编写一个新函数来以较小的尺寸而不是实际尺寸显示该图像,以加快加载速度。另外,我想将另一个功能的图像显示为裁剪图像。
如何以最快的方式调整大小和裁剪图像以节省等待时间?
pip install python-resize-image
例如
from PIL import Image
from resizeimage import resizeimage
with open('test-image.jpeg', 'r+b') as f:
with Image.open(f) as image:
cover = resizeimage.resize_cover(image, [200, 100])
cover.save('test-image-cover.jpeg', image.format)