0
点赞
收藏
分享

微信扫一扫

PIL图片批量转换格式,python

sullay 2022-03-20 阅读 171
python
import os, sys
from PIL import Image

path = os.getcwd().replace("\\", "/")



for file in os.listdir(path):
    if ".jpg" in file:
        new_file = file.split(".")[-2]+".png"
        print(new_file)
        new_image = Image.open(path +"/"+ file)
        new_image.save(path +"/"+ new_file)
        

原理很简单,就是用PIL.Image打开后再保存为另一种格式。

举报

相关推荐

0 条评论