Skip to content Skip to sidebar Skip to footer

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 like this: than

Solution 1:

You can do something like this:

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

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

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

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

Solution 2:

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

Solution 3:

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.

<?phpinclude_once('get.php');

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

Post a Comment for "Get Base64 Php String Into Img Tag"