Display image in PHP given image content

181 Views Asked by At

I'm using the GrabzIt PHP library and it returns screenshots of webpages.

The library returns the image content to be saved as a file, e.g:

file_put_contents('images/screenshot.png', $grabzitImageContents);

I want to display this image in the page without saving the image (uses server space). Is it possible?

2

There are 2 best solutions below

3
On BEST ANSWER

You could just send the header and then echo the data:

header("Content-Type: image/png");
echo $grabzitImageContents;

Try it.

0
On

You could use a data URI:

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