首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python/Wand/Imagemagick:添加标题

Python/Wand/Imagemagick:添加标题
EN

Stack Overflow用户
提问于 2021-09-13 23:28:22
回答 1查看 124关注 0票数 0

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

代码语言:javascript
复制
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)

最后,我想复制这个命令:

代码语言:javascript
复制
convert Lenna.jpg -fill white -undercolor '#00000080' -pointsize 24 -gravity SouthEast -annotate +50+10 "Some text here" Lenna2.jpg

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

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-09-14 00:41:56

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

代码语言:javascript
复制
    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,最后一行需要更改。

代码语言:javascript
复制
    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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69170115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档