0
我有一点不寻常的问题。我使用Pillow和Python 3,我需要阻止它的一部分变得透明和分层。某个点后切割图像
正如你可以在图片1中看到,头发略微剪辑帽子在左,它的权利。
图像2是一个我编辑自己,是正确的。左侧或右侧没有裁剪。
所有3个精灵(头部,帽子和头发)都是透明的,尺寸相同。
麻烦的是我可以使它在某个点切断,但不是所有的我的帽子精灵在同一个地方开始和结束。例如,有些人可能会做弧形,并且最终会在弧线中没有头发。
这是我使用的代码:
from PIL import Image, ImageTk, ImageChops
background = Image.open("headbase.png")
foreground = Image.open("hair2.png")
Image.alpha_composite(background, foreground).save("test3.png")
background2 = Image.open("test3.png")
foreground2 = Image.open("testhat2.png")
Image.alpha_composite(background2, foreground2).save("testo.png")