如何在ImageMagick中绘制文本和阴影?

时间:2013-12-31 13:45:22

标签: text imagemagick draw shadow imagemagick-convert

我正在使用转换在图片上打印一些文字,我想用黑色阴影装饰文字,我尝试 -blur - 高斯但我无法应用于文本,它仅适用于背景图像。 我需要使用 -draw 命令,而不是 -annotate

这是我需要更新阴影的代码

-font "geometricslab703bt-bold-webfont.ttf" -fill White -pointsize 18 -draw "rotate -4 text 350,250 '---- mijn ideale ----'"

提前致谢

2 个答案:

答案 0 :(得分:3)

使用文本阴影的更好,更灵活的方法是在新图层上渲染阴影。此方法允许您根据需要操纵阴影文本,而不会影响背景。最后在调整任何几何偏移后,在阴影顶部绘制实际文本。这是一个例子:

convert -size 280x100 pattern:SMALLFISHSCALES \
  \( xc:transparent -font "Menlo" -pointsize 32 -fill black -draw "rotate -4 text 20,60 'ImageMagick'" -blur 0x1 \) \
  -geometry +2+2   -composite \
  -font "Menlo" -fill white -pointsize 32 -draw "rotate -4 text 20,60 'ImageMagick'" \
  example.png

逃脱的大括号" \( \)"将创建一个新的子图像;其中,将使用-composite标志应用于背景。

enter image description here

这个解决方案需要更多的劳动力,但会隔离所有效果。

答案 1 :(得分:1)

您可以使用caption来绘制文本,并使用clone制作阴影层,然后合并这两层。

convert logo: -resize 40%x40 \
    \( -size "80x40" -background none -gravity west  -fill green caption:"Caption text" \
    \( +clone -background navy -shadow 80x3+5+5  \) +swap -background none -layers merge +repage \) -composite \
    \( -size "80x40" -background none -gravity east  -fill green caption:"Caption text"  \
    \( +clone -background red -shadow 80x3+5+5  \) +swap -background none -layers merge +repage \) -composite \
    out.png

enter image description here

相关问题