【问题标题】:How do I get text bounding box drawn with pgmagick如何获得用 pgmagick 绘制的文本边界框
【发布时间】:2016-10-21 09:47:54
【问题描述】:

我通过 pgmagick 在图像上成功绘制了一些文本:

from pgmagick.api import Image
img = Image((300, 200))
img.annotate('Hello World')
img.write('helloworld.png')

但是如何获取文本的边界框呢?谁能帮帮我?

【问题讨论】:

    标签: imagemagick graphicsmagick pgmagick


    【解决方案1】:

    我对@9​​87654321@ 一无所知,但如果我向您展示一些您可以在命令行中使用 ImageMagick 执行的操作,也许会有所帮助。

    选项 1

    使用label 为所需文本创建一个足够大的画布,然后询问 ImageMagick 该画布的几何形状有多大:

    convert label:"Hello world" -format %G info:
    62x15
    

    因此,“Hello world”的默认字体大小为 62 像素宽和 15 像素高。

    选项 2

    或者,像你一样使用-annotate,然后问ImageMagick如果你修剪掉它周围多余的空间会有多大:

    convert -size 300x200 xc:red -annotate +10+20 "Hello world" -format %@ info:
    61x8+10+12
    

    选项 3

    创建画布并对其进行注释,然后对其进行修剪并获取大小:

    convert -size 300x200 xc:red -annotate +10+20 "Hello world" -trim info:
    xc:red XC 61x8 300x200+10+12 16-bit sRGB 0.000u 0:00.000
    

    选项 4

    创建画布、注释、修剪、保存然后获取结果尺寸:

    convert -size 300x200 xc:red -annotate +10+20 "Hello world" -trim result.png
    
    identify result.png
    result.png PNG 61x8 300x200+10+12 16-bit sRGB 887B 0.000u 0:00.000
    

    也许(希望)您可以将其中之一改编为pgmagick

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-26
      • 2017-05-21
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多