How can I insert a PHP generated PNG image into my html?

Viewed 156

I'm generating a png image using php that works here:

http://www.sidesay.co/BTC_spark.php

However I am attempting to then insert the generated png file into a table on a webpage (I'm unsure if that's terribly inefficient). I use the php line:

    echo "<td><img src=\"https:\/\/www.sidesay.co\/BTC_spark.php\" ></td>";

I get a broken image, but if I right click and select "load image" it works.

Should I instead first run the php file and save the image separately before destroying it? If so, how?

Thanks in advance.

1 Answers

Your BTC_spark.php script is outputing HTML itself:

<html>
<body>
<img src='/libraries/Sparkline/sparkline.php?size=80x20&data=2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16&back=fff&line=5bb763&fill=d5f7d8' />
</body>
</html>

Change it to just output the img src:

/libraries/Sparkline/sparkline.php?size=80x20&data=2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16&back=fff&line=5bb763&fill=d5f7d8

... and then in your main script, stick this output in a variable:

$mypic = file_get_contents('./BTC_spark.php');
echo '<td><img src="'.$mypic.'"></td>';
Related