当输入图像以纯数据格式接收给我时,如何在http响应中调整图像大小?

问题描述 投票:-1回答:1

我是Django的新手,最近我写了一个有关图像表示的项目。

在我看来,我有一个功能可以显示图像。但是我首先从加密/解密服务中下载了映像。这意味着下载的图像为纯数据字节格式。

现在,我想编写一个新函数来以较小的尺寸而不是实际尺寸显示该图像,以加快加载速度。另外,我想将另一个功能的图像显示为裁剪图像。

如何以最快的方式调整大小和裁剪图像以节省等待时间?

django image-resizing
1个回答
0
投票
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)

来自https://pypi.org/project/python-resize-image/

© www.soinside.com 2019 - 2024. All rights reserved.