写了个脚本,自动将文件夹内的图片转成WebP格式,并加上网址水印
import os
from PIL import Image
def convert_to_webp(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
file_path = os.path.join(root, file)
image = Image.open(file_path)
webp_path = file_path.rsplit('.', 1)[0] + '.webp'
image.save(webp_path, 'webp')
convert_to_webp('.')