【问题标题】:Python/Wand/Imagemagick: Adding captionPython/Wand/Imagemagick:添加标题
【发布时间】:2021-11-09 04:26:34
【问题描述】:

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

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

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

谢谢。

【问题讨论】:

  • 你为什么认为有问题?
  • 为什么在 Python Wand 中不用注释而不是标题?
  • 谢谢。很难找到正确的文档(用于 python/wand)。我尝试了注释并得到了它,但找不到更改字体颜色的选项。我期待它是 font_color 或 text_color,但都不存在。我在深色背景上收到深色字母。
  • 尝试在注释之前设置 fill_color 和/或 stroke_color 属性
  • 谢谢。我发现了一些其他的帖子。它适用于 Windows,但在 Linux 上我得到 AttributeError: 'Image' object has no attribute 'annotate'。

标签: python imagemagick wand


【解决方案1】:

这是一个可行的解决方案(但仅适用于 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    • 2015-04-25
    相关资源
    最近更新 更多