让我以免责声明为前缀,当我对成像/图形全部使用时一无所知,因此也许我对这里的某些内容缺乏基本的了解。
我正在尝试将图片(game_image
)粘贴到基本图片(image
)上,并overlay_image
在顶部覆盖一个透明的叠加层(),以为文本添加一些暗度。
这是预期结果的示例:
这是我当前代码生成的示例:
这是我当前的代码:
from PIL import Image, ImageFont, ImageDraw
# base image sizing specific to Twitter recommended
base_image_size = (1600, 900)
base_image_mode = "RGBA"
base_image_background_color = (0, 52, 66)
image = Image.new(base_image_mode, base_image_size, base_image_background_color)
# game_image is the box art image on the left side of the card
game_image = Image.open("hunt.jpg")
image.paste(game_image)
# overlay_image is the darkened overlay over the left side of the card
overlay_image = Image.new(base_image_mode, base_image_size, (0, 0, 0))
overlay_image.putalpha(128)
# x position should be negative 50% of base canvas size
image.paste(overlay_image, (-800, 0), overlay_image)
image.save("test_image.png", format="PNG")
您会看到游戏图像的某种形式继承了叠加层的透明度。我怀疑这与mask
我上面的粘贴中添加的内容有关,但我尝试研究什么是掩蔽及其掩盖,在我发现的任何情况下我都无法理解。
感谢您对理解为什么会发生和/或如何解决的任何帮助!
您非常亲密...您需要使用Image.alpha_composite
代替paste
。因此,代码的最后两行应为:
image = Image.alpha_composite(image, overlay_image)
image.save("test_image.png", format="PNG")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句