tim c
tim c

Reputation: 99

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:

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

thanks for your help!

Upvotes: 0

Views: 2214

Answers (3)

David Fern&#225;ndez
David Fern&#225;ndez

Reputation: 544

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

Upvotes: 2

Marcel
Marcel

Reputation: 28087

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).'">';

Upvotes: 0

Sabeen Malik
Sabeen Malik

Reputation: 10880

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

Upvotes: 0

Related Questions