Draw text not working
-
evolveimg
Draw text not working
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.
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
Code: Select all
echo exec("/usr/bin/convert xc:yellow -resize 200x15! -gravity \"Center\" -draw \"text 0,0 'Test Text'\" $blank_image");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");-
evolveimg
Re: Draw text not working
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");
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
What version are you using ?
Try adding the error output and see what it comes up with.
I tend to use -annotate rather than -draw these days
Code: Select all
<?php
echo "<pre>";
system("convert -version");
echo "</pre>";
?> 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>";
?> 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>";
?> - anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
- Contact:
Re: Draw text not working
NOTE you will need to set -fill, -pointsize and -font BEFORE the operation that is using in (the -draw).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");
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");http://www.imagemagick.org/Usage/text/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
evolveimg
Re: Draw text not working
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?
Array
(
[0] => convert: unable to read font `/usr/share/fonts/default/Type1/n021003l.pfb'.
)
1
What do I do?
-
evolveimg
Re: Draw text not working
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
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
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
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\">";
?>
Last edited by Bonzo on 2009-05-07T10:15:10-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
- Contact:
Re: Draw text not working
Too old!!!!! (450 versions behind) You really need to upgrade.
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 7 guests