I am trying to produce multi-colored text image with Imagemagick and PHP. The following code works, but I cannot insert a space after each word. I have tried various settings, nothing is working. Should I use annotate or draw text command instead of label? Label seems to be simple to use here.
$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);
Update: Solution
Remarks: Spaces do not work in command line. So, I need to escape double quotes with a forward slash.
This has worked:
$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";
Thank you all, especially Fred!
In your case it seems like it would be better to use -annotate
once you want to insert multiple texts instead of using -label
.
Example of use of -annotate
: http://www.imagemagick.org/Usage/annotating/#gravity_text