gpt4 book ai didi

python - PIL : How to make area transparent in PNG?

转载 作者:太空狗 更新时间:2023-10-29 17:38:54 33 4
gpt4 key购买 nike

我一直在用PIL裁剪图片,现在我也想把某些矩形区域做成透明的,比如说

from PIL import Image
im = Image.open("sample.png")
transparent_area = (50,80,100,200)
...

最佳答案

from PIL import Image
from PIL import ImageDraw
im = Image.open("image.png")
transparent_area = (50,80,100,200)

mask=Image.new('L', im.size, color=255)
draw=ImageDraw.Draw(mask)
draw.rectangle(transparent_area, fill=0)
im.putalpha(mask)
im.save('/tmp/output.png')

我学会了怎么做here .

关于python - PIL : How to make area transparent in PNG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4379978/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com