Page 1 of 1

including generated png graph

Posted: Fri Oct 05, 2007 6:35 am
by paulmcg
Hi there, first post with a question. Hope it's not too silly.

I've got a nice frame consisting of a table within a table, links to the left and whatever link is clicked on that php page is included on the right.

This has been working fine so far for a lot of things however I'm using a few pages to gather information via forms from a user which then go and query a db and generate a graph of the users' choice. This graph is a png file.

Now my problem is that i can only make a link to the png file and view solely the graph and nothing else however if i try and include the page which generates and displays the png file all i get is the code which one would get if they tried to open a png file using notepad in the middle of my table.

How do I get the image in the table and not the code "‰PNG ... etc"? Is it because I'm using include?

image

Posted: Fri Oct 05, 2007 6:53 am
by N1gel
If you generate a PNG can you not just show it like you would a normal image.

Code: Select all

<img src="graph.png" alt="Graph" />
http://www.w3schools.com/tags/tag_img.asp

Posted: Fri Oct 05, 2007 6:58 am
by paulmcg
that would be great, if i could but my code looks something like this, I've truncated it for simplicity

Code: Select all

$im = imagecreatetruecolor($width,$height );

//then lots of stuff to generate the graph

//part to display the graph

Header('Content-type: image/png');
Imagepng ($im);
echo $im;
Now if i create it so my browser goes to this page it's fine. But all i can see is the image and nothing else.

If I want it so my image is embedded in my webpage all i get is that nasty text i mentioned earlier.

Posted: Fri Oct 05, 2007 7:09 am
by N1gel
Ok i've never worked with these image things. But based on what i have just read on the php website could you save the image as a file and reference that.

imagecreatetruecolor

imagepng

Code: Select all

$im = imagecreatetruecolor($width,$height );

//then lots of stuff to generate the graph

//part to display the graph

Imagepng ($im,'TempGraph.png');

echo "<img src='TempGraph.png' alt='Graph' />";
Don't know if that will help

Posted: Fri Oct 05, 2007 7:21 am
by paulmcg
That seems to have solved that problem

Thanks very much!