图像裁剪脚本现在显示损坏 link

Image cropping script now showing broken link

多年来我一直在使用以下 PHP 脚本。几周前,它突然停止工作。它创建的图像又被嵌入到网页中,显示为断开的链接。如果我删除内容类型行(发送文本),图像文本似乎发送正常。我有一个单独的脚本来获取图像,使用这个脚本来裁剪它们,然后在本地保存输出。我查看了保存的 .png 文件。它们都有一个文件大小(30k 左右)。

我担心我的托管服务已经更新 PHP 并且(再次)损坏了一些东西。有人知道发生了什么事吗?

#!/usr/bin/php -q
<?
$w=$_GET['w'];
$h=isset($_GET['h'])?$_GET['h']:$w;
$x=isset($_GET['x'])?$_GET['x']:0;
$y=isset($_GET['y'])?$_GET['y']:0;
$filename="http://".$_GET['src'];
//echo $filename;
$result_array = getimagesize($filename);
//exit();

if ($result_array !== false) {
    $mime_type = $result_array['mime'];
    switch($mime_type) {
        case "image/jpeg":
            header('Content-type: image/jpeg');
            $image = imagecreatefromjpeg($filename); 
            break;
        case "image/gif":
            header('Content-type: image/gif');
            $image = imagecreatefromgif($filename); 
            break;
        case "image/png":
            header('Content-type: image/png');
            $image = imagecreatefrompng($filename); 
            break;
        case "image/bmp":
            header('Content-type: image/bmp');
            $image = imagecreatefrombmp($filename); 
            break;
        default:
            echo "Unsupported image type";
    }

    $resized = imagecreatetruecolor(1200, 1200);
    imagecopyresampled($resized, $image, 0, 0, 0, 0, 1200, 1200, imagesx($image), imagesy($image));
    $crop = imagecreatetruecolor($w,$h);
    imagecopy ( $crop, $resized, 0, 0, $x, $y, $w, $h );
    imagepng($crop);
} else {
    echo "file is not a valid image file";
} 

?>

啊,那句老话"if you ask a question on stack overflow, you'll figure out the problem a minute later"又应验了。

几乎可以肯定我的主机已更新 PHP。由于某种原因,行 #!/usr/bin/php -q 被添加到 PNG 文件的开头。我删除了那条线,一切都恢复了。