Question

I have begun exploring of GDI functions in PHP. I wrote the following code

<?php 
echo"GDI FUNCTIONS"; 
$im=imageCreate(500,200);
$colorBg=imageColorAllocate($im,150,150,100);
$colorText=imageColorAllocate($im,0,0,0);
imageString($im,1, 20, 20, 'George', $colorText);
header("Content-type: image/gif");
imageGif($im);
imageDestroy($im);
?>

PHP 5.2.13 GD2 Extension in PHP.net exists; I Have reinstalled php and have restarted apache server.

but still picture not displayed. I have tried in all browsers like (Google chrome, IE, opera and etc.). but only a little rectangle is displayd at left-upper corner.

Even text 'GDI FUNCTION' not displayed. (PHP works fine!!!)

PHP_info shows thad GD is enabled.

Was it helpful?

Solution

The problem is that you are echoing text before sending a header. This results in a PHP warning and a invalid image binary. Simply remove echo"GDI FUNCTIONS"; and it should work.

Also not that all (AFAIK) GD functions are lowercase.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top