【问题标题】:Add space between each word in multi-colored text image在多色文本图像中的每个单词之间添加空格
【发布时间】:2015-10-31 00:28:46
【问题描述】:

我正在尝试使用 Imagemagick 和 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";

谢谢大家,尤其是 Fred!

【问题讨论】:

  • 尝试使用\n。不是100%肯定,但你可以试试。或连接"convert ... code... . " " . etc.
  • 嗨 Fred,我需要将所有这些词放在一行中。 '\n' 我认为会创建多行。
  • 我对此有一种感觉。我在上面编辑了我的评论以尝试连接。 IE。 "convert . " " . etc 事物的类型。
  • $multi-color-text 应该是一个变量吗?
  • @Phellipe,$multi-color-text 是一个变量。

标签: php imagemagick


【解决方案1】:

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

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

【讨论】:

  • “你试过了吗” 答案最好作为 cmets,其中我已经将 OP 留在了他们的问题之下,其中包含使用注释的问答。
  • 确实@Fred-ii-,我已经重写了答案。我没有看到你的评论。
  • @Phellipe,你和 Fred 还建议在这里使用 -annotate。会用的。
  • 没问题Phellipe。 @AnayBose 考虑接受他的回答,以便结束问题并将其标记为已解决,cheers
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-11
  • 1970-01-01
  • 2011-05-29
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多