Sending/Displaying a base64 encoded Image

If you set content-type to image/jpeg, you should give just the jpeg data, without the base64 crap. But you’re treating the result as if it was html.

You’re effectively building a data uri, which is ok, but as you noted, only as an uri. So leave the content type as it is (text/html), and

echo '<img src="data:image/jpeg;base64,'.base64_encode($image_data).'">';

and you’re good to go.

Leave a Comment