I have a base64 encoded string that I would like to convert into an image in PHP / HTML.
Here is what I have:
$data = "R0lGODdhAAGAAKIAAP38+/3h3cjN5P3HwgAAAP8AoP8AGv8EIywAAAAAAAGAAAAD....."; echo base64_decode($data);
// OR
echo '<img src="data:image/gif;base64,' . base64_decode($data) . '" />';
None of those work. Any suggestions?
Much appreciated! Catalin
In the first case you should add this before echoing the decoded image data:
header("Content-type: image/gif");
In the second case, use this instead:
echo '<img src="data:image/gif;base64,' . $data . '" />';
Display Image using base64_encode function
$ret = fopen($fullurl, 'r', true, $context); $contents = stream_get_contents($ret); $base64 = 'data:image/PNG;base64,' . base64_encode($contents); echo "<img src=$base64 />" ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With