Page 1 of 1

Graphics does not work with PHP

Posted: Sat Mar 06, 2004 7:25 pm
by anmol
Hello I just installed PHP and apache on my machine. I need to get some quick graphics work But when drawing images, the image does not get drawn. The font functions work but not the image ones! can anyone help me out with this?

Sincerely,

Anmol Misra

Posted: Sat Mar 06, 2004 7:44 pm
by Steveo31
Code?

:)

The code which is problematic

Posted: Sat Mar 06, 2004 9:25 pm
by anmol
<?php
$im = ImageCreate(200,200);
$white= ImageColorAllocate($im,0xFF,0xFF,0xFF);
$black= ImageColorAllocate($im,0x33,0x37,0x10);
ImageFilledRectangle($im,100,100,150,150,black);
ImageString($im,5,50,160,"A Black Box",$black);
header('Content-Type: image/gif');
ImagePNG($im);
?>

Posted: Sat Mar 06, 2004 9:41 pm
by markl999
Change ImageFilledRectangle($im,100,100,150,150,black);
to
ImageFilledRectangle($im,100,100,150,150,$black);

...and it works (for me anyway). On a side note, if you 'view source' it will tell you any problems, ie it told me '<b>Notice</b>: Use of undefined constant black - assumed 'black''

does it mean i have to use $black everytime!

Posted: Sun Mar 07, 2004 4:24 am
by anmol
hi does it means that I have to use $black i mean instead of black everytime. Coz the book says it is just black.

Did it work for you without $ sign infront of black. What can be the reason?

Sincerely,

Anmol Misra

Posted: Sun Mar 07, 2004 4:28 am
by markl999
No, you have to use $black. Without it the code would be looking for a defined constant, like define ('black', 'somevalue'); the $ means a variable, $black, which you have defined above .. $black= ImageColorAllocate($im,0x33,0x37,0x10);