开发者

get base64 php string into img tag

Ive got a php file 'get.php' that echo's a base64 string.

How would i display this as an image in another .php page?

something li开发者_高级运维ke this:

<img src="get.php?id=$lastid">

thanks for your help!


You can do something like this:

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

but if you BASE64STRING is the output of a php, then something like this would work:

<img src="data:image/png;base64, <?php include 'get.php?id=$lastid' ?>>

I know it may not be exactly but I hope you get the idea


If you want to display that as an image you will need to look into GD Library and generate a run time image using a function like imagettftext() after the image has been generated, your PHP script will send a header saying this is an image something like

header( "Content-type: image/jpeg"); 

and then echo the binary data of the generate image.

I found this question for you which should help you get started, look at the accepted answer: Text on a image


No, you need to echo the output of get.php directly. Why don't you just include and call that function on the original page in source? Don't forget that the base64 string needs data:image/png;base64, or similar at the beginning.

<?php

include_once('get.php');

echo '<img src="'.base64img($lastid).'">';
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜