PHP 脚本不起作用 GD 库已安装


PHP script not working GD Library installed

下面是我的调整大小.php脚本。我需要安装 GD 库并这样做了,但我仍然无法让图像像以前一样处理我的旧服务器。这里 您可以看到错误报告创建了一个空映像,并显示以下错误:

Warning: getimagesize(http://stackoverflow.com/questions/19817599/../wp-content/themes/Explorable/panos/Pano__0000.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/go3de/public_html/wp-content/themes/Explorable/resize.php on line 16

Warning: Division by zero in /home/go3de/public_html/wp-content/themes/Explorable/resize.php on line 19

Warning: Division by zero in /home/go3de/public_html/wp-content/themes/Explorable/resize.php on line 30

出了什么问题?请帮忙!

<?php session_start();header("Pragma: public");header("Cache-Control: max-age = 604800");
header("Expires: ".gmdate("D, d M Y H:i:s", time() + 604800)." GMT");
function thumbnail($image, $width, $height) {
    if($image[0] != "/") { // Decide where to look for the image if a full path is not given
        if(!isset($_SERVER["HTTP_REFERER"])) { // Try to find image if accessed directly from this script in a browser
            $image = $_SERVER["DOCUMENT_ROOT"].implode("/", (explode('/', $_SERVER["PHP_SELF"], -1)))."/".$image;
        } else {
            $image = implode("/", (explode('/', $_SERVER["HTTP_REFERER"], -1)))."/".$image;
        }
    } else {
        $image = $_SERVER["DOCUMENT_ROOT"].$image;
    }
    $image_properties = getimagesize($image);
    $image_width = $image_properties[0];
    $image_height = $image_properties[1];
    $image_ratio = $image_width / $image_height;
    $type = $image_properties["mime"];
    if(!$width && !$height) {
        $width = $image_width;
        $height = $image_height;
    }
    if(!$width) {
        $width = round($height * $image_ratio);
    }
    if(!$height) {
        $height = round($width / $image_ratio);
    }
    if($type == "image/jpeg") {
        header('Content-type: image/jpeg');
        $thumb = imagecreatefromjpeg($image);
    } elseif($type == "image/png") {
        header('Content-type: image/png');
        $thumb = imagecreatefrompng($image);
    } else {
        return false;
    }
    $temp_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($temp_image, $thumb, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
    $thumbnail = imagecreatetruecolor($width, $height);
    imagecopyresampled($thumbnail, $temp_image, 0, 0, 0, 0, $width, $height, $width, $height);
    if($type == "image/jpeg") {
        imagejpeg($thumbnail);
    } else {
        imagepng($thumbnail);
    }
    imagedestroy($temp_image);
    imagedestroy($thumbnail);
}
if(isset($_GET["h"])) { $h = $_GET["h"]; } else { $h = 0; }
if(isset($_GET["w"])) { $w = $_GET["w"]; } else { $w = 0; }
thumbnail($_GET["img"], $w, $h);
?>

您尝试调整大小的图像有多大?看起来它在抱怨内存不足?

尝试分配更多内存。

您可以尝试在页面顶部添加以下内容:ini_set("memory_limit","512M");...看看它是否有效。

想通了!我在最初的<?php开始标签之前有一个空格,这导致了错误!啊!对不起,我是菜鸟!