Page 1 of 1
Draw text not working
Posted: 2009-05-06T08:33:22-07:00
by evolveimg
Hi I'm new to Imagemagick and I'm struggling to add text to images. I've been messing with the following php code with no success:
echo exec("/usr/bin/convert xc:yellow -resize 200x15! -gravity \"Center\" -draw \"text 0,0 'Test Text'\" $blank_image");
The image defined in $black_image becomes a 200x15 yellow rectangle with no text. I get no errors. I have no idea what I'm doing wrong. Please help. Thanks.
Re: Draw text not working
Posted: 2009-05-06T08:50:50-07:00
by Bonzo
Code: Select all
echo exec("/usr/bin/convert xc:yellow -resize 200x15! -gravity \"Center\" -draw \"text 0,0 'Test Text'\" $blank_image");
You do not need the echo
You MAY be able to use convert and not /usr/bin/convert
You are not resizing so you need -size not -resize
Center does not need the \"
You could add the font details e.g. font size and colour
Try:
Code: Select all
exec("/usr/bin/convert -size 200x15 xc:yellow -gravity Center -draw \"text 0,0 'Test Text'\" $blank_image");
Re: Draw text not working
Posted: 2009-05-06T08:58:56-07:00
by evolveimg
Still only a yellow rectangle with that code and this:
exec("/usr/bin/convert -size 200x15 xc:yellow -gravity Center -draw \"text 0,0 'Test Text'\" -fill black -pointsize 14 -font Times-Roman $blank_image");
Re: Draw text not working
Posted: 2009-05-06T09:30:03-07:00
by Bonzo
What version are you using ?
Code: Select all
<?php
echo "<pre>";
system("convert -version");
echo "</pre>";
?>
Try adding the error output and see what it comes up with.
Code: Select all
<?php
$array=array();
echo "<pre>";
exec("/usr/bin/convert -size 200x15 xc:yellow -gravity Center -draw \"text 0,0 'Test Text'\" $blank_image 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
I tend to use -annotate rather than -draw these days
Code: Select all
<?php
$array=array();
echo "<pre>";
exec("/usr/bin/convert -size 200x15 xc:yellow -gravity Center -fill black -annotate +0+0 \" Test Text \" $blank_image 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
?>
Re: Draw text not working
Posted: 2009-05-06T17:03:08-07:00
by anthony
evolveimg wrote:exec("/usr/bin/convert -size 200x15 xc:yellow -gravity Center -draw \"text 0,0 'Test Text'\" -fill black -pointsize 14 -font Times-Roman $blank_image");
NOTE you will need to set
-fill,
-pointsize and
-font BEFORE the operation that is using in (the
-draw).
however instead creating an empty yellow box and drawing into it you could -annotate into it whcih does not have the quotes within quotes problem.
Also why create a empty yellow box! create a label of that -size! If pointsize is NOT set IM will attempt to find a point size that best fits an image of that size!
Code: Select all
exec("/usr/bin/convert -size 200x15 -background yellow -gravity Center -font Times-Roman label:'Test Text' $blank_image");
See IM examples, Text Handling
http://www.imagemagick.org/Usage/text/
Re: Draw text not working
Posted: 2009-05-07T08:33:35-07:00
by evolveimg
Ah thank you. I'm getting this error:
Array
(
[0] => convert: unable to read font `/usr/share/fonts/default/Type1/n021003l.pfb'.
)
1
What do I do?
Re: Draw text not working
Posted: 2009-05-07T08:34:19-07:00
by evolveimg
Also this is my version:
Version: ImageMagick 6.0.7 04/20/08 Q16
http://www.imagemagick.org
Copyright: Copyright (C) 1999-2004 ImageMagick Studio LLC
Re: Draw text not working
Posted: 2009-05-07T10:14:18-07:00
by Bonzo
Your version of Imagemagick is probably about 4 years old but I do not know if that is a problem.
I would simplify things and upload a ttf font into the same folder as the code and try that, change this to the actual font name font.ttf
Code: Select all
<?php
$array=array();
echo "<pre>";
exec("/usr/bin/convert -size 200x15 xc:yellow -gravity Center -fill black -pointsize 16 -font font.ttf -annotate +0+0 \" Test Text \" output.jpg 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
echo "<img src=\"output.jpg\">";
?>
Re: Draw text not working
Posted: 2009-05-07T10:14:57-07:00
by fmw42
Too old!!!!! (450 versions behind) You really need to upgrade.