python3 load image in memory or save image to memory

 

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()

 

 

When processing images, this method does not use temporary files, and all processing is only performed in memory.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326514911&siteId=291194637