python3加载内存中的图像或保存图像到内存

from PIL import Image
from io import BytesIO
import urllib.request

def getimg(url)
    data = urllib.request.urlopen(url).read()
    im = Image.open(BytesIO(data))
    #...
    img_file = BytesIO()
    im.save(img_file, 'JPEG')
    return img_file.getvalue()

在处理图片时,这个方式可以不使用临时文件,所有处理只在内存进行。

猜你喜欢

转载自23497465-qq-com.iteye.com/blog/2383511