0

I'm trying to scale an image and return it with the image header. It works to just display the image as it is, but as soon as I try to scale it, nothing shows on the webpage.

<?php
if(isset($_GET["width"])) {
    $size = $_GET["width"] <= 1000 ? $_GET["width"] : 1000;
    $imageFile = file_get_contents('no-image.png', true);
    $image = imagescale($imageFile, $size);
    
    header("Content-Type: image/png");
    header("Content-Length: " . getimagesize($image));
    echo $image;
    return;
}
?>

I used the filesize() method to get the filesize of the image directly on the server, but that method did only support a string so I'm not sure if the getimagesize() method is causing the issue here. Any idea?

Thanks in advance!

Martin O
  • 41
  • 1
  • 7
  • the return value from imagescale is a resource, you need to use `imagepng($image)` instead of echoing it – Lawrence Cherone Apr 26 '21 at 16:39
  • That's weird, echoing it worked when I didn't scale it. Seems to give the same results though, still nothing shows. – Martin O Apr 26 '21 at 16:41
  • Either the file is corrupted or you go into the else case (which is not present here) or you have an error => either way, have you [activated error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)? – Definitely not Rafal Apr 26 '21 at 16:45
  • I do have a value present in the $_GET["width"]. I tried to activate error reporting at the top of the document earlier, but that caused this to show on the webpage, and ignoring everything in the file pretty much. https://gyazo.com/c6ec72e2808ae4854faf6fcd7db6c427 – Martin O Apr 26 '21 at 16:47

0 Answers0