在多色文本图像中的每个单词之间添加空格


Add space between each word in multi-colored text image

我正在尝试使用Imagemagik和PHP生成多色文本图像。以下代码有效,但我不能在每个单词后面插入空格。我尝试了各种设置,但都不起作用。我应该使用注释或绘制文本命令而不是标签吗?标签在这里使用起来似乎很简单。

$file = 'font.ttf'; 
$command = "convert -background white -fill black -font $file -pointsize 80 -density 90 label:New  -fill black -font $file -pointsize 80 -density 90 label:Here -fill red -font $file -pointsize 80 -density 90 label:? +append $multi-color-text.png"; 
exec($command);

更新:解决方案

备注:空格在命令行中不起作用。所以,我需要用一个正斜杠来转义双引号。

这已经奏效了:

$command = "convert -background white -fill black -font $file -pointsize 80 -density 90 label:'"New '"  -fill black -font $file -pointsize 80 -density 90 label:'"Here '" -fill red -font $file -pointsize 80 -density 90 label:? +append $multi-color-text.png";

谢谢大家,尤其是弗雷德!

在您的情况下,如果您想插入多个文本,则最好使用-annotate,而不是使用-label

-annotate的使用示例:http://www.imagemagick.org/Usage/annotating/#gravity_text