PHP image resize function doesn't work properly?

677 views Asked by At

I am using this function to resize images but it causes an error

Call to undefined function resize()

Here is my source:

$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;
}   

Why do I get this error ?

1

There are 1 answers

0
p0d4r14n On

Code error:Call to undefined function resize()

means it does not have access to that function. If its in a different php file you have to include that first

include 'functions.inc.php';