使用 Imagemagick 将带有阴影的 2 个文本字符串添加到背景

Using Imagemagick to add 2 text strings with drop shadow to a background

我正在尝试将 2 个带注释的文本放置到不同位置的背景上,并为文本提供字体阴影。单个文本效果很好,但是当我添加第二个文本时,它模糊了背景和图像的其余部分。

图片结果如下:https://imgur.com/a/VW09KIy

第一个命令按预期工作:

convert ~/.backgrounds/White.jpg -font Bitter -pointsize 72 -annotate +130+170 'Anthony' -blur 0x4 -fill white  -annotate +125+165 'Anthony' font_shadow_fuzzy.jpg

第二个把一切都搞砸了,我需要知道如何解决它。

convert ~/.backgrounds/White.jpg -font Bitter -pointsize 72 -annotate +130+170 'Anthony' -blur 0x4 -fill white  -annotate +125+165 'Anthony'  -annotate +230+270 'Anthony' -blur 0x4 -fill white  -annotate +225+265 'Anthony' font_shadow_fuzzy.jpg

您使用 Imagemagick 命令时遇到的问题是 第二个 -blur 会影响第一个文本。所以你需要对每个文本单独处理,并把它放在一个透明的背景上。然后将两个结果拼合到白色背景上。

以下适用于 Imagemagick 6.9.10.9 Q16 Mac OSX Sierra:

convert \
\( -size 600x400 xc:none -font ubuntu -pointsize 72 -fill black -annotate +130+170 'Anthony' -blur 0x4 -fill white  -annotate +125+165 'Anthony' \) \
\( -size 600x400 xc:none -font ubuntu -pointsize 72 -fill black -annotate +230+270 'Anthony' -blur 0x4 -fill white  -annotate +225+265 'Anthony' \) \
-background white -flatten \
font_shadow_fuzzy.jpg


目前似乎无法上传,所以这里是 link 结果:

http://www.fmwconcepts.com/misc_tests/font_shadow_fuzzy.jpg

你没有说你的白色背景图片有多大。因此,如果我假设它是 600x400,那么我将创建一个并修改命令。您可以使用任何其他背景,但需要知道文本的透明背景有多大。

convert -size 600x400 xc:white white.jpg

convert white.jpg \
\( -size 600x400 xc:none -font ubuntu -pointsize 72 -fill black -annotate +130+170 'Anthony' -blur 0x4 -fill white  -annotate +125+165 'Anthony' \) \
\( -size 600x400 xc:none -font ubuntu -pointsize 72 -fill black -annotate +230+270 'Anthony' -blur 0x4 -fill white  -annotate +225+265 'Anthony' \) \
-flatten \
font_shadow_fuzzy2.jpg


或者,对于任何大于您要放置文本的位置的任意背景,您可以找到尺寸并按如下方式进行处理:

infile="white.jpg"
dim=`convert "$infile" -format "%wx%h" info:`
convert "$infile" \
\( -size $dim xc:none -font ubuntu -pointsize 72 -fill black -annotate +130+170 'Anthony' -blur 0x4 -fill white  -annotate +125+165 'Anthony' \) \
\( -size $dim xc:none -font ubuntu -pointsize 72 -fill black -annotate +230+270 'Anthony' -blur 0x4 -fill white  -annotate +225+265 'Anthony' \) \
-flatten \
font_shadow_fuzzy3.jpg


另一种方法是在白色背景上制作两个带有阴影的小文本图像作为单独的图像。黑色模糊文本的偏移量为 +5+5,白色未模糊文本的偏移量为 +0+0。对两个图像执行此操作,然后使用 -geometry 作为偏移量以所需的偏移量将它们合成到背景白色图像上。