Python 格式化工具

快速格式化、压缩和美化 Python 代码

from PIL import Image

# 打开图片
image_path = 'test.png'  # 替换为你的文件路径
image = Image.open(image_path)

if image.mode != 'RGBA':
    image = image.convert('RGBA')
else:
    print("图像已为RGBA模式")

background_color = (255, 255, 255)
pixels = image.load()

for y in range(image.height):
    for x in range(image.width):
        r, g, b, a = pixels[x, y]
        if (r, g, b) == background_color:
            pixels[x, y] = (r, g, b, 0)
        else:
            pixels[x, y] = (r, g, b, a)