批量修改webp为jpg

1次阅读
没有评论

批量修改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

正文完
 0
116博客
版权声明:本篇文章由 116博客 于2024-11-27发表,共计697字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码