2

let's say I have the following:

$image = imagecreatefromjpeg($filePath);
echo imagejpeg($image);

is it possible to display this as image without the need to display the headers (which will block other html rendering? or must I split it to several files?

hakre
  • 184,866
  • 48
  • 414
  • 792
Itai Sagi
  • 5,341
  • 12
  • 47
  • 73

1 Answers1

3

The only way to just stick an image in a page is to encode it as base64, like this:

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

There are serious limitations in doing it like this. Instead, you should be referring to a separate script for your image:

<img src="yourimagescript.php" />
Community
  • 1
  • 1
Brad
  • 152,561
  • 47
  • 332
  • 504