0

As the title says, I want to create a file that returns an image from an external server without downloading / storaging it. I tried something with PHP headers, but it didn't work as intended (I can't find the code right now sorry). For example, if we have an image_displayer.php file.

image_displayer.php?url=https://example.com/images/epic_image.png

This URL should return the "https://example.com/images/epic_image.png" image. This image will be displayed from an HTML file from the same server. I couldn't get it working with PHP headers (it was giving problems in the HTML file) It doesn't have to be in PHP. It doesn't matter to me. Thanks in advance.

aphelios
  • 52
  • 5
  • Are you using it in an image tag? You can base64_encode(epic_image) in the php-file. https://stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html – Patrick Aug 10 '22 at 09:52
  • @Patrick since i can't edit the HTML, i can't use that. Thanks anyway! – aphelios Aug 10 '22 at 13:16

1 Answers1

1

You could try something like this:

$image_data = file_get_contents(IMAGE_URL);
$image_resource = imagecreatefromstring($image_data);

header('Content-Type: image/png');
imagepng($image_resource);
imagedestroy($image_resource);

If you just want to quickly show the image without handling it, you could simply do a 301 redirect to it.

tom_nb_ny
  • 110
  • 10