利用Python 批量转换png到jpg

2019-07-25  本文已影响0人  michaelxwang
import os
import sys

from PIL import Image

input_folder=r'D:\png'  #源文件夹,包含.png格式图片
output_folder=r'D:\jpg'# 输出文件夹
#training_data=[]    
a=[]
for root, dirs, files in os.walk(input_folder):
    for filename in (x for x in files if x.endswith('.jpg')):
        filepath = os.path.join(root, filename) 
        
        object_class = filename.split('.')[0]
        a.append(object_class)
    print(a)
    
for i in a:
    old_path=input_folder+"\\"+str(i)+'.jpg'
    new_path=output_folder+"\\"+str(i)+'.png'
    img=Image.open(old_path)
    img.save(new_path)
上一篇下一篇

猜你喜欢

热点阅读