[vox-tech] PHP GD Issues

Richard S. Crawford rscrawford at mossroot.com
Wed Nov 16 10:16:53 PST 2005


I'm starting to mess around with PHP-GD for the first time, and I'm
encountering an issue that's bugging me: the only image I get is just a
black box, even if I set the color to white.

Here's the code in question:

<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$im = imagecreatetruecolor(400, 50);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 204, 204, 204);
$black = imagecolorallocate($im, 0, 0, 0);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = '/path/to/font/arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

...and the image it creates:

http://mossroot.com/imgtest.php

Looking at phpinfo(), I see that GD is installed, TTF support is enabled,
and FreeType support is enabled as well.  And I know that GD works on the
server, since I've got a couple of applications that use it and use it
successfully.  But all I get is this black box.

Any help would be greatly appreciated.
-- 
Richard S. Crawford
http://www.mossroot.com
"That which does not kill me makes me stranger."
--Llewellyn


More information about the vox-tech mailing list