Images and text

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
User avatar
Luis Almeida
Forum Commoner
Posts: 33
Joined: Tue Apr 01, 2003 4:22 am

Images and text

Post by Luis Almeida »

Hi,

After doing the following code I just can´t output any text with "ECHO" or "PRINTF" functions.
I mean. It does all the graphics stuff but it just don´t execute the line "echo "Image 1;"
Can any one help me please???

$pic=imageCreate($boxWidth,$boxHeight);
imageFilledRectangle($pic, $boxLeft+1, $boxTop, $boxRight-1, $boxBottom, imageColorAllocate($pic,$boxGray,$boxGray,$boxGray));
imageFilledRectangle($pic, $boxLeft, $boxTop+1, $boxRight, $boxBottom-1, imageColorAllocate($pic,$boxGray,$boxGray,$boxGray));
Header("Content-type: image/png");
imagePNG($pic);
imageDestroy($pic);
echo "IMAGE 1";
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

User avatar
Luis Almeida
Forum Commoner
Posts: 33
Joined: Tue Apr 01, 2003 4:22 am

Post by Luis Almeida »

I know that I can use "ImageString" to write on images but my problem is to write on the page using "ECHO" or "Printf" after displaying the image
User avatar
ILoveJackDaniels
Forum Commoner
Posts: 43
Joined: Mon May 20, 2002 8:18 am
Location: Brighton, UK

Post by ILoveJackDaniels »

You've got a line saying this: Header("Content-type: image/png"); so the browser thinks the page being displayed is a picture. It won't display normal text as well.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

As ILoveJackDaniels said, you can't tell the browser you want to display an image and then expect it to be able to deal with text as well. If you want to add text you can either put the text on the image or, if for instance the image creation script was in a file called imagecreate.php, you could do:

Code: Select all

<img src="imagecreate.php" alt="PHP generated image" />
<p>Image 1</p>
Mac
User avatar
Luis Almeida
Forum Commoner
Posts: 33
Joined: Tue Apr 01, 2003 4:22 am

Thanks

Post by Luis Almeida »

Thank you for concerning
that worked just fine
Post Reply