from PIL import Image# 打开图片文件img = Image.open('example.png')# 将图片转换为带 Alpha 通道的模式img = img.convert('RGBA')# 将所有白色像素替换为透明像素data = img.getdata()new_data = []for pixel in data:if pixel[0] == 255 and pixel[1] == 255 and pixel[2] == 255:new_data.append((255, 255, 255, 0))else:new_data.append(pixel)img.putdata(new_data)# 保存处理后的图片img.save('example_transparent.png')
Copyright © 2023 leiyu.cn. All Rights Reserved. 磊宇云计算 版权所有 许可证编号:B1-20233142/B2-20230630 山东磊宇云计算有限公司 鲁ICP备2020045424号
磊宇云计算致力于以最 “绿色节能” 的方式,让每一位上云的客户成为全球绿色节能和降低碳排放的贡献者