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

时间:2018-08-07 15:19:23

标签: imagemagick

我试图将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

1 个答案:

答案 0 :(得分:1)

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


目前似乎无法进行上传,因此以下是结果的链接:

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作为偏移量将它们以所需的偏移量合成到背景白色图像上。