【发布时间】:2020-11-03 15:13:48
【问题描述】:
当我尝试使用此代码时,输出为全黑图像:
img = Image.open("image.png")
font = ImageFont.truetype("ArialCE.ttf", size)
text = Image.new(mode = "RGBA", size= (400,375))
draw = ImageDraw.Draw(new_image)
text = input_text
draw.text((x,y), text, (0,0,0), font = font)
text.save("saved.png")
img.paste(text, (0,0))
img.save("text.png")
我正在使用枕头库,我希望将“文本”图像粘贴到 img 上。
谢谢
【问题讨论】:
-
您在黑色图像上绘制黑色文本...
-
我认为RGBA支持alpha??我已经将文本图像写成 RGBA 了??
-
Image.new()默认创建黑色图像... pillow.readthedocs.io/en/stable/reference/… -
你为什么要创建一个新图像,在其上绘制文本,然后粘贴到背景上?为什么不直接在背景上绘制文字?
-
我这样做是因为我想用文字旋转图像
标签: python python-imaging-library