tags:

views:

60

answers:

2

All,

I am executing a PHP script through CURL which returns a PNG file as an output. How can I show the png file in a php web page?

+2  A: 
echo '<img src="urltotheimage.php" alt="Alt text" />';
Jeffrey Aylesworth
+1  A: 

First of all, why do you need to fetch a PNG through CURL? There's better ways to get a image from server, for example using the <img /> tag..

Anyways, I assume you are getting the binary data in a variable, you can output the image by setting appropriate headers and echoing the data:

header('Content-type: image/png');
echo $image;
Tatu Ulmanen
The issue is i am generating the image using imagefrompng() function in pchart. When I try to display this on browser, I get a bunch of characters instead of the image file. I am not sure how to display that file in the browser
Vincent
Then this method should work. The strange characters are the binary data of the PNG file which the browser tries to output as HTML. If you specify the proper content type (image/png), it should show up just fine.
Tatu Ulmanen
I wanted to show multiple graphs on the same page. It's not working when called through an MVC controller-Model architecture.
Vincent