Python/Wand/Imagemagick:添加标题



我正在尝试复制一些注释示例。下面是我的代码,我想知道出了什么问题。

from wand.font import Font
from wand.image import Image
from wand.display import display

file1 = 'Lenna.jpg' #Download from here https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png
myImage = Image(filename=file1)
myImage.font = Font('C:\Users\User1\Documents\FONTS\cyrvetic.ttf')
myImage.GRAVITY_TYPES=("southeast")
myImage.caption = ("Some text here",50,50,200,200)
display(myImage)

最后我想复制这个命令:

convert Lenna.jpg -fill white -undercolor '#00000080' -pointsize 24 -gravity SouthEast -annotate +50+10 "Some text here" Lenna2.jpg

你知道上面的代码出了什么问题吗?

谢谢。

这是一个有效的解决方案(但只适用于Windows,不适用于Linux)

from wand.drawing import Drawing
from wand.color import Color
with Drawing() as ctx:
ctx.font_family = 'Times New Roman, Nimbus Roman No9'
ctx.font_size = 28
ctx.fill_color = Color('blue')
ctx.stroke_color = Color('blue')
ctx.gravity = "south_east"
myImage.annotate("Some text", ctx, 20, 30) #Windows

对于Linux,最后一行需要修改

from wand.drawing import Drawing
from wand.color import Color
with Drawing() as ctx:
ctx.font_family = 'Times New Roman, Nimbus Roman No9'
ctx.font_size = 28
ctx.fill_color = Color('blue')
ctx.stroke_color = Color('blue')
ctx.gravity = "south_east"
#myImage.annotate("Some text", ctx, 20, 30) #Windows
ctx.text(20, 30, "Some text") #Linux
ctx.draw(myImage) #Linux

最新更新