webp格式图片转换为jpg
1.将本地的webp图片转换为jpg
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‘)
2. 将下载的webp格式图片直接保存为jpg
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‘)
相关推荐
jusewe 2019-12-18
benico 2020-07-04
jackalwb 2020-06-21
cyydjt 2020-05-11
seekerhit 2020-04-20
JingLisen 2020-04-23
chinademon 2020-04-15
kingzone 2019-12-14
FrederickBala 2019-12-08
Liuzqi 2019-10-30
89540596 2019-11-18
88226330 2019-11-13
丁一鸣的CSDN 2011-03-09
chancle 2016-06-03
ice00 2011-05-26