本帖最后由 ttyylfd 于 2024-3-29 11:32 编辑
批量修改webp为jpg,双击运行后,会自动将当前目录下的webp后缀的图片全部改为jpg。
自用的,不喜勿喷,谢谢!
[Python] 纯文本查看 复制代码 import os
from PIL import Image
def convert_images(directory, original_ext, target_ext):
for filename in os.listdir(directory):
if filename.endswith(original_ext):
original_file = os.path.join(directory, filename)
target_file = os.path.join(directory, os.path.splitext(filename)[0] + target_ext)
try:
with Image.open(original_file) as img:
img.convert('RGB').save(target_file, quality=95)
os.remove(original_file)
except Exception as e:
print(f'Error converting file {filename}: {e}')
your_directory_path = '.'
convert_images(your_directory_path, '.webp', '.jpg')
下载:https://wwp.lanzoul.com/ipGeb1t1gsyf 密码:52pj
下面这个是webp变GIF的:
下载:https://wwp.lanzoul.com/i5i9l1t1ii6j 密码:52pj |