Forum Moderators: coopster

Message Too Old, No Replies

PHP image functions don't allow me to use print()

no matter where i put it.

         

someone

6:10 pm on Nov 1, 2004 (gmt 0)

10+ Year Member



I made a poll which takes the user's vote and turn it into a pie graph. Everything works fine except when I wanted to print the poll question on top of the pie graph, it doesn't let me do it. I understand this is due to the header function: header("Content-type: image/jpeg");

which i must pass through the page first before anything is passed. So I put the header function the first thing on the page, then put some print() functions the end of the page. But it still doesn't allow me to print anything. Is it just not possible to use print() when I use those image functions? Thank You.

DrDoc

6:31 pm on Nov 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP image functions don't allow me to use print()
no matter where i put it

You answered your question yourself...

print
is not an image function, it's a text function.

Image Functions [php.net]

someone

7:31 pm on Nov 1, 2004 (gmt 0)

10+ Year Member



To clarify what I wanted to say:

I want something like this:

-------------------------------------
the poll title here in words

the pie graph here

the total # of votes here in words
-------------------------------------

the pie graph is working fine, now I want to put the title in words somewhere above the pie graph, since it's just a title, i don't want to make that into an image, so I tried using the print() to print the title out, but didn't work. same with the total # of votes in words. I saw it on other sites, where they are able to do what I want, but of course, I don't know how they did it.

jatar_k

7:40 pm on Nov 1, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> so I tried using the print() to print the title out, but didn't work

did you get an error?
did you check the source in the browser to see if it was actually output but not displaying when rendered?
did you try using echo or some such other output function?

mincklerstraat

8:12 pm on Nov 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



someone, it's possible you're stuck in a basic misunderstanding that a lot of first-time image users have (if not, sorry for bringing this up, but lots of people make this mistake).

When you use php to produce images, think like this: the php script is the image. You put the image on your page like any other image, except the extension is a php extension instead of the usual .jpg or .png or whatever - like this:

<img src="phpimagescript.php" alt="image generated by php" />

So the image part is a whole separate script, a separate file, from the part of your php that's producing the HTML page with text.

print() and echo() output things - but images consist of binary output. So in your image script, you put the header there, like you mention, and then you just use image functions, and no echo or print (unless you're a real image genious and know how to insert the right binary stuff at the right place). 'Text' you see on images is not like text on webpages - it's just pixel combos, and in binary format.

What you want to use is

imagestring()
or
imagettftext()
.