我尝试使用ImageMagick创建文本图像,其中笔划仅向外扩展。 I found a solution,我应该使用“-draw”命令,但有了它我需要我的图像大小,但我不提前知道。
下面的命令应该升级。不知何故,我需要再次在其上绘制文本,没有笔画宽度:
convert -background none -fill white -pointsize 100 -stroke red \
-strokewidth 20 label:text stroke.png
@ leu的解决方案差不多好,但新文本的定位并不是很好。我的结果是上面的,我不知道,我在哪里犯了错误:
答案 0 :(得分:1)
我的建议:将label:"Some text"
与-annotate "Some text"
合并。像这样:
#myfont="Arial-Black-Standard"
#myfont="Tahoma"
#offset="-0-0"
#offset="-20-10"
#offset="-30-10"
#offset="-10+10"
myfont="Tahoma"
offset="+10+10"
convert -respect-parentheses \
\( \
-font "${myfont}" \
-pointsize 180 \
-strokewidth 18 \
-fill blue \
-stroke blue \
-background none \
label:"Test text" \
\) \
-gravity center \
-font "${myfont}" \
-pointsize 180 \
-fill white \
-annotate "${offset}" "Test text" \
result${offset}.png
使用offset=...
变量(也包括磅值和笔触宽度)来更接近您想要的效果。以下是我的一些结果:
然而,就像@MarkSetchell一样,我并不完全理解你想要实现的目标。
答案 1 :(得分:0)
是的:在你的照片上绘制相同的文字 - 也许是通过将你的命令的输出传递到另一个转换
convert -background none -fill white -pointsize 100 -stroke red \
-strokewidth 20 label:text png:- \
| convert -fill white -pointsize 100 -stroke none \
-draw 'text 10,82 "text"' - stroke.png
诀窍是正确放置第二个字符串。 x位置是笔划宽度的一半,但是y位置似乎依赖于字体和点数。我的方法是当strokewidth设置为0时首先将两个字符串放在一起:
convert -background none -fill white -pointsize 100 -stroke red \
-strokewidth 0 label:text png:- \
| convert -fill white -pointsize 100 -stroke none \
-draw 'text 0,72 "text"' - stroke.png
然后你必须将一半的笔画宽度添加到这个y位置。
获得正确的y位置有点试错,但它似乎适用于任何字符串。
== edit ==
当然,我们不需要做反复试验。但相反,我们可以使用ImageMagick的力量。只需执行以下步骤(在Bash中的此示例中):
#!/bin/bash
# read text from command line (or use "Test Text")
text=${1:-"Test Text"}
# strokewidth
sw=20
# pointsize
ps=120
# font
font=Arial
# result file
result="stroke.png"
# do some calc
sw_half=$(expr $sw / 2)
convert -background none -font $font -fill white -pointsize $ps -stroke red -strokewidth $sw label:"$text" $result
convert -background none -font $font -fill white -pointsize $ps -stroke none label:"$text" png:- | composite -geometry +${sw_half}+${sw_half} - $result $result
您可以通过
获取系统中可用的字体列表convert -list font
这个想法和上面的想法一样:绘制文本两次,然后使用偏移量为行程宽度的一半而将一个绘制到另一个上。
结果如下所示