Jump to content

[SOLVED] GD Images and HTML


flyersun

Recommended Posts

I've found a great GB lib which lets me easily and quickly create graphs using PHP but I can't seem to incorporate the graphs into a html page when I try I get the following error.

 

 

JpGraph Error: HTTP headers have already been sent.

Caused by output from file allusersbar.php at line 3.

Explanation:

HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).

 

Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.

 

For example it is a common mistake to leave a blank line before the opening "<?

 

Does anyone know a way I can get around this?

Link to comment
https://forums.phpfreaks.com/topic/88813-solved-gd-images-and-html/
Share on other sites

yes you are making the image inside the script it is being presente and thus you are trying to redistribute headers

 

i.e

<?php
echo "<html>";

function make_graph(){
#This produces a graphh
header("Content-type: image/jpeg");
}

echo "<img src=\"".make_graph()."\" />";
#that will not work
?>

 

YOu have that or some varient of it

I did a quick browse of that script's web site and did not see any examples showing how to display the image on a web page. I guess they assume that if you are using their script you know HTML and what tags to use to place an image onto a web page - http://w3schools.com/html/html_images.asp

 

The url in the src="url" parameter of the <img tag would need to be to a .php script that outputs your gd produced image/graph. Something like -

 

<img src="mygraph.php" alt="">

 

mygraph.php is the script that produces and outputs the graph, including a header() with a Content-type: that matches the type of image you are generating.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.