from PIL import Image
import os
def save_image(input_name, output_name):
if os.path.isdir(input_name):
name = os.listdir(input_name)
for fileName in name:
if fileName.find(".webp")!=-1:
im = Image.open(input_name+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]) # 3 is the alpha channel
im = background
im.save('{}.jpg'.format(fileName.replace(".webp","")),'JPEG')
else:
im = Image.open(input_name)
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]) # 3 is the alpha channel
im = background
im.save('{}.jpg'.format(output_name),'JPEG')
input_name = input("请输入文件夹路径或者文件路径:")
output_name = "试一试"
save_image(input_name,output_name)
- THE END -
最后修改:2020年11月16日
非特殊说明,本博所有文章均为博主原创。
如若转载,请注明出处:https://www.95app.top/webp%e8%bd%acjpg/