python处理图片增加alpha通道

from PIL import Image
import os

# course_resources
allPngs = []
path = "./course_resources"
for root, dirs, files in os.walk(path, topdown = False):
    for name in files:
        allPngs.append(os.path.join(root, name))
    for name in dirs:
        allPngs.append(os.path.join(root, name))

for path in allPngs:
    # 
    if '.png' in path:
        # 
        im = Image.open(path)
        imBackground = im.resize((591, 827))
        imBackground = imBackground.convert('RGBA')
        imBackground.save(path, "PNG")
        print(path)

欢迎留言

avatar
  Subscribe  
Notify of