Hello, dear! On the eve did the function of reducing the size of the image. So, it does not work to bring it into working condition. Namely, the $source variable does not want to be passed from the switch as the 2nd parameter to imagecopyresized .
Notice: Undefined variable: source in .../functions.php on line 97 Warning: imagecopyresized() expects parameter 2 to be resource, null given in .../functions.php on line 97 Notice: Undefined variable: source in .../functions.php on line 111 Warning: imagedestroy() expects parameter 1 to be resource, null given in .../functions.php on line 111 What could be the reason? I do on a lokalka.
Here is the source code:
function thumImg($file) { $ext = strtolower(strrchr(basename($file), '.')); $prefix = 'thum_'; $th = "thum/"; // $extension = array('.jpg', '.gif', '.png'); $imgname = basename($file); $sas = getimagesize($file); $width = $sas[0]; $height = $sas[1]; if ($width >= $height) { $newwidth = 200; $newheight = $height / ($width / 200); } else { $newwidth = $width / ($height / 200); $newheight = 200; } $thumb = imagecreatetruecolor($newwidth, $newheight); switch ($ext) { case '.jpg': $source = imagecreatefromjpeg($file); break; case '.gif': $source = imagecreatefromgif($file); break; case '.png': $source = imagecreatefrompng($file); break; } imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); switch ($ext) { case '.jpg': imagejpeg($thumb, $th . $prefix . $imgname); break; case '.gif': imagegif($thumb, $th . $prefix . $imgname); break; case '.png': imagepng($thumb, $th . $prefix . $imgname); break; } imagedestroy($thumb); imagedestroy($source); }
I beg you to help with advice. Google did not give anything adequate. Help php too. Also, could you explain the imagecopyresized function to imagecopyresized , namely, what is the 2nd parameter (Source image link resource)? That is the source for the image of what? Thanks in advance.
var_dump($file, $ext)and give the result. A, and an example call. I am plagued by vague doubts) - Sh4dow