我使用以下代码创建缩略图。当它是一个单独的php页面时,它工作得很好。但是,当我将其转换为功能并在我的上传页面中使用它时,它会创建黑色图像。请帮忙
$filename='something.jpg'; //filename
if(preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg('upload/'.$filename);
} else if (preg_match('/[.](gif)$/', $filename)) {
$im = imagecreatefromgif('upload/'.$filename);
} else if (preg_match('/[.](png)$/', $filename)) {
$im = imagecreatefrompng('upload/'.$filename);
}
$nx=400; //size of thumbnail to be create
$ny=300;
$ox = imagesx($im);
$oy = imagesy($im);
$nm = imagecreatetruecolor($nx, $ny);
$path='upload/';
imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
if(!file_exists($path)) {
if(!mkdir($path)) {
die("There was a problem. Please try again!");
}
}
imagejpeg($nm, $path . $filename);