批量将RGBA图片转换成RGB格式

首先,下面的代码图片必须是从0开始到21结束,比如:0.jpg等,可以看我的上一篇博客,怎么把图片的文件名从0开始进行命名。之后,就是复制粘贴就可以。

转换后保存的文件夹为:work_path_new

from PIL import Image
#-- coding: UTF-8 --



work_path = r'C:\Users\Administrator\Desktop\project\3'
work_path_new = r"C:\Users\Administrator\Desktop\project\3_new"
count = "0"

for i in range(21):
    print(work_path)
    im = Image.open(work_path+"\\"+count+".jpg")
    print(im)
    #此时返回一个新的image对象,转换图片模式
    image=im.convert('RGB')
    #调用save()保存
    image.save(work_path_new+"\\"+count+".jpg")

    count = int(count)
    count = count + 1
    count = str(count)


猜你喜欢

转载自blog.csdn.net/qq_44666320/article/details/126703551
今日推荐