PIL图片批量转换格式,python

sullay

关注

阅读 171

2022-03-20

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)

0 0 举报