2

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?

apparatix
  • 1,492
  • 7
  • 22
  • 37

2 Answers2

1

You could use a data URI:

$encoded = base64_encode($grabzitImageContents);
echo '<img src="data:image/png;base64,' . $encoded . '" />';
cmbuckley
  • 40,217
  • 9
  • 77
  • 91
1

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

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

Try it.

GregPK
  • 1,232
  • 11
  • 17
  • This won't work if the OP's intention is to display it directly within an HTML page. – cmbuckley Nov 28 '12 at 21:18
  • Haha that's the first thing I tried. I think there's something wrong with the GrabzIt code because neither answer is working. Lemme check... – apparatix Nov 28 '12 at 21:19
  • @apparatix This should work, but your script should only echo out this and nothing else. The source of the image in the html would be the image generating script. – jeroen Nov 28 '12 at 21:20