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
  • 193,403
  • 52
  • 435
  • 836
Itai Sagi
  • 5,537
  • 12
  • 49
  • 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
  • 159,648
  • 54
  • 349
  • 530