python如何实现webp图片格式转化?
发布时间:2022-03-12 13:50:19 所属栏目:语言 来源:互联网
导读:这篇文章给大家分享的是有关python实现webp图片格式转化的内容。小编觉得挺实用的,因此分享给大家做个参考,下文有具体的实例,接下来一起跟随小编看看吧。 1、将本地的webp图片转换为jpg 2、将下载的webp格式图片直接保存为jpg 代码如下: 1、将本地的webp
|
这篇文章给大家分享的是有关python实现webp图片格式转化的内容。小编觉得挺实用的,因此分享给大家做个参考,下文有具体的实例,接下来一起跟随小编看看吧。 1、将本地的webp图片转换为jpg 2、将下载的webp格式图片直接保存为jpg 代码如下: 1、将本地的webp图片转换为jpg from PIL import Image filename = 'xxxxxxxxxx.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 = 'http:xxxxx.JPG' # 需要下载的图片地址 headers = {} # 请求头,按需添加 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]) im.save('xxx.jpg', 'JPEG') ![]() (编辑:平顶山站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |


