开发者

Show png file on Web page

All,

I am executing a PHP script thro开发者_如何学Pythonugh CURL which returns a PNG file as an output. How can I show the png file in a php web page?


echo '<img src="urltotheimage.php" alt="Alt text" />';


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;


as you are receiving the string representing the png and if that is base64 encoded then you can embed directly on the image tag as follows:

<img src="data:image/png;base64,aAbBcCdDeEfFgGhH..." />

where aAbBcCdDeEfFgGhH... would be the image string.

see more on data uri's here: http://en.wikipedia.org/wiki/Data_URI_scheme#Inclusion_in_HTML_or_CSS_using_PHP

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜