【发布时间】:2020-05-29 19:18:20
【问题描述】:
让我先声明一下,我对图像/图形一无所知,所以也许我对这里的某些东西缺乏基本的了解。
我正在尝试将图像 (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 有关,但我尝试研究掩蔽是什么,并且在我发现它的任何上下文中都超出了我的理解范围。
感谢任何帮助理解为什么会发生这种情况和/或我如何解决的问题!
【问题讨论】:
标签: python python-3.x python-imaging-library