【发布时间】:2016-10-03 04:11:25
【问题描述】:
是否有可能以某种方式获得在图像魔术中绘制的文本的宽度?
我当前的转换命令如下所示:
convert -size 720x480 -background #000 xc:black -fill white -stroke 白色的 \ -font Arial -pointsize 18 \ -draw "text 72,370 'NavP1'" \ -font Arial -pointsize 18 \ -draw "text , ''" \ -font Arial -pointsize 18 \ -draw "text , ''" \ -font Arial -pointsize 18 \ -draw "text 370,370 'Extras'" \ -font Arial -pointsize 18 \ -draw "text 430,370 'opt'" \ -font Arial -pointsize 18 \ -draw "text 550,370 'NavP1'" \ C:\xampp\htdocs\labelText.bmp
我以编程方式完成此操作,并希望根据我有多少导航点来居中和对齐导航点
(我从我的 php 公式/数据库中获得导航点的数量)。
这是我的意思以及它应该是什么样子的一个小草图
________________________________________
| |
| |
| |
| navp1 navp2 |
|_______________________________________|
________________________________________
| |
| |
| |
| navp1 navp2 navp3 |
|_______________________________________|
我为该图像设置了固定宽度(720 像素)。
因此我有最少 2 个导航点和最多 6 个导航点。
我的想法是,如果我能得到每个导航(文本/文字)点的宽度,我就可以正确计算和对齐这些点。
但是我知道我找不到可以做到这一点的函数。
我尝试了 Mark Setchell 答案,但我的命令似乎有错误
convert -debug annotate -size 720x480 -background #000 xc:black -fill white -stroke white \ -font Arial -pointsize 18 \ -draw "text 72,370 'nav1'" \ -font Arial -pointsize 18 \ -draw "text 180,370 'nav2'" \ -font Arial -pointsize 18 \ -draw "text 430,370 'nav3'" \ -font Arial -pointsize 18 \ -draw "text 550,370 'nav4'" \ C:\xampp\htdocs\test.bmp
但我收到以下错误消息:
没有定义图像'-background'@ 错误/convert.c/ConvertImageCommand/325
【问题讨论】:
-
你能简化你的命令吗?所有
-size设置的意义何在,据我所知,除了第一个设置之外,您不需要任何设置。此外,-font和-pointsize是 "settings",与-fill和-stroke相同,因此它们在更改之前保持设置,因此您可以删除除第一个之外的所有内容。 -
好吧,我把它简化了一点,希望对你有帮助
-
它不起作用,因为
#是一个注释字符,所以你需要转义或引用它——或者只使用black -
好的,现在我得到了这个错误:无法打开 iamge '\':没有这样的文件或目录@错误
标签: php image algorithm imagemagick imagemagick-convert