Page 1 of 1

imagettftext

Posted: Sun Jul 13, 2008 6:44 pm
by SidewinderX
I've been trying to get this code to work for the past two hours:

Code: Select all

<?php
// Set the content-type
header("Content-type: image/png");
 
// Create the image
$im = imagecreatetruecolor(400, 30);
 
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $black);
 
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
putenv('GDFONTPATH=' . realpath('.'));
$font = 'Arial-Black.ttf';
 
 
// Add the text
imagettftext($im, 20, 0, 10, 20, $white, $font, $text);
 
 
imagepng($im);
imagedestroy($im);
?>
It is giving me this error:
The image “http://localhost/shout/images/window.php” cannot be displayed, because it contains errors.
And I narrowed it down to this line of code

Code: Select all

imagettftext($im, 20, 0, 10, 20, $white, $font, $text);
I uploaded it to a remote webserver and it worked fine - so I am fairly confident it is not my code. What do I need to compile php with for this to work? imagecreatefronpng() works fine.

Here is my current configuration:
./configure --disable-magic-quotes --enable-bcmath --enable-sockets --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --with-png --with-ttf --enable-gd-native-ttf --with-regex=system
[/quote]

Thanks,
John