PHP图像调整大小功能无法正常工作?

时间:2014-12-20 05:03:36

标签: php image-processing getimagesize

我正在使用此功能调整图像大小,但会导致错误

Call to undefined function resize()

这是我的来源:

$w=280;
$h=280;
resize($w,$h);

function resize($width, $height)
{
    list($w, $h) = getimagesize($_FILES['image']['tmp_name']);
    /* calculate new image size with ratio */   
    $ratio = max($width/$w, $height/$h);
    $h = ceil($height / $ratio);
    $x = ($w - $width / $ratio) / 2;
    $w = ceil($width / $ratio);
    $folder="../images/";
    /* new file name  */   
    $path = $folder.$_FILES['image']['name'];
    $update = mysql_query("update `detail` set `url` = '".$path."' where `id` = '".$id."'");
    $image = imagecreatefromstring($imgString);
    $tmp = imagecreatetruecolor($width, $height);
    imagecopyresampled($tmp, $image,0, 0,$x, 0,$width, $height,$w, $h);
    /* Save image */   
    switch ($_FILES['image']['type']) {
        case 'image/jpeg':
            imagejpeg($tmp, $path, 100);
            break;
        case 'image/png':
            imagepng($tmp, $path, 0);
            break;
        case 'image/gif':
            imagegif($tmp, $path);
            break;
        default:
            exit;
            break;
    }
    return $path;
}   

为什么我会收到此错误?

1 个答案:

答案 0 :(得分:0)

代码错误:调用未定义的函数resize()

表示它无权访问该功能。 如果它在不同的php文件中你必须包含第一个

include 'functions.inc.php';