批量bmp修改格式为png

import os

os.system("pip3 install pillow")
from PIL import Image


def con(input, output):
    bmp_image = Image.open(input)
    bmp_image.save(output, format='png', quality=95)


def _dir(_d):
    for i in os.listdir(_d):
        t = os.path.join(_d, i)
        if os.path.isfile(t) and t.split(".")[-1] == 'bmp':
            out = t.replace(".bmp", '.png')
            con(t, out)
        elif os.path.isdir(t):
            _dir(t)


# 文件夹
_d = r""
# 处理
_dir(_d)

posted @ 2023-06-21 12:40  love_water  阅读(65)  评论(0)    收藏  举报