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()
在处理图片时,这个方式可以不使用临时文件,所有处理只在内存进行。