我不确定您的要求是什么,但我猜您想在图像“下方”写一个标签。这是wand库的示例。
from wand.image import Image
from wand.compat import nested
from wand.color import Color
from wand.font import Font
with nested(Image(filename='logo:'),
Image(filename='null:')) as (source, text):
text.font = Font('Impact', 64)
text.read(filename='label:Hello world!')
largest_width = max(source.width, text.width)
offset = (largest_width - min(source.width, text.width)) / 2
with Image(width=largest_width,
height=source.height + text.height,
background=Color('WHITE')) as dst:
dst.composite(source, 0, 0)
dst.composite(text, int(offset), source.height)
dst.save(filename="output.png")

概述
with nested(Image(filename='logo:'),
Image(filename='null:')) as (source, text):
创建两个图像。您将负责logo:
用您的 ByteIO 缓冲区替换图像。该null:
图像是用于分配魔杖实例的占位符。
text.font = Font('Impact', 64)
text.read(filename='label:Hello world!')
这定义了要绘制的字体和文本。该label:
协议可以替换caption:
为其他行为。
with Image(width=largest_width,
height=source.height + text.height,
background=Color('WHITE')) as dst:
创建第三个“空白”图像,该图像足够大以包含两个图像。
dst.composite(source, 0, 0)
dst.composite(text, int(offset), source.height)
将图像数据从source
&复制text
到新图像。