关于webp,png,jpg图片转换
参考博客:从Python中的目录转换所有文件(.jpg到.png) - 问答 - Python中文网 (cnpython.com)
因为想给Sakura多配一些背景图试试效果,网站一个个转换太慢而且还要手动改名字,因此写了个脚本
首先把要转换的图片都放到665243.py旁边
from PIL import Image
import os
#可以将打开的图像转换为RGB,然后将其保存为任何格式。
#directory = r'D:\PATH'
directory = r'D:\f盘\python\pycharm\222\666'
c=10
for filename in os.listdir(directory):
if filename.endswith(".jpg"):
im = Image.open(filename)
name='('+str(c)+')'+'.jpg'+'.webp'
rgb_im = im.convert('RGB')
rgb_im.save(name)
c+=1
print(os.path.join(directory, filename))
continue
else:
continue
然后复制到cdn文件夹上传就行了,很方便
tips:
要放到.py的同级目录下,不然会报错
这个也可以实现从jpg,png之类相互转换,输出文件名格式参数是name,自己调