Graphics does not work with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anmol
Forum Newbie
Posts: 7
Joined: Sat Mar 06, 2004 7:25 pm

Graphics does not work with PHP

Post 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
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Code?

:)
anmol
Forum Newbie
Posts: 7
Joined: Sat Mar 06, 2004 7:25 pm

The code which is problematic

Post 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);
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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''
anmol
Forum Newbie
Posts: 7
Joined: Sat Mar 06, 2004 7:25 pm

does it mean i have to use $black everytime!

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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);
Post Reply