标签:name 本地 form load rom 地址 requests pen header
from PIL import Image
filename = ‘0bb521255dc1eb1830579959afff9407.webp‘
im = Image.open(filename)
if im.mode == "RGBA":
im.load() # required for png.split()
background = Image.new("RGB", im.size, (255, 255, 255))
background.paste(im, mask=im.split()[3])
save_name = filename.replace(‘webp‘, ‘jpg‘)
im.save(‘{}‘.format(save_name), ‘JPEG‘)
from io import BytesIO
from PIL import Image
import requests
# 这里url是你需要下载的图片地址
resp = requests.get(url, headers=headers)
byte_stream = BytesIO(resp.content)
im = Image.open(byte_stream)
# im.show()
if im.mode == "RGBA":
im.load() # required for png.split()
background = Image.new("RGB", im.size, (255, 255, 255))
background.paste(im, mask=im.split()[3])
name = md5_(url)
im.save(‘./photo2/{}.jpg‘.format(name), ‘JPEG‘)
标签:name 本地 form load rom 地址 requests pen header
原文地址:https://www.cnblogs.com/JeromeLong/p/13234876.html