错误代码:
# pip install Pillow
import PIL.Image as Image
# 以第一个像素为准,相同色改为透明
def transparent_back(img):
img = img.convert('RGBA')
L, H = img.size
print(L, H)
# color_0 = (255, 255, 255, 255) # 要替换的颜色
for h in range(H):
print()
for l in range(L):
dot = (l, h)
color_1 = img.getpixel(dot)
print("%15s"%(color_1), end=' ')
if color_1[0] > 210 and color_1[1] > 210 and color_1[2] > 210:
list = (color_1[0], color_1[1], color_1[2], 0)
img.putpixel(dot, list)
# else:
# list = (255, 255, 255, 255)
# img.putpixel(dot, list)
# print(type(color_1))
# if color_1 == color_0:
# color_1 = color_1[:-1] + (0,)
# img.putpixel(dot, color_1)
return img
if