저는 며칠 동안 이것을 알아 내려고 노력했습니다. 이미지를 업로드하고 정사각형으로 자르고 300x300 크기로 조정 한 다음 150x150으로 크기를 조정하고 'uploads/products/$ id /'폴더에 업로드 한 다음 파일 경로를 mysql 데이터베이스로 이동해야합니다.php imagecreatefrom 결과가 검은 색입니다.
그러나 검은 색 이미지가 계속 출력됩니다. 이 스크립트에 무슨 문제가 있습니까?
$ext = explode('.', $_FILES['image1']['name']);
$extension = $ext[1];
$target_path = 'uploads/products/'.$id.'/';
$filename = 'featuredpic.'.$extension;
$featured100_full_path = $target_path.$filename;
if(!is_dir('../../../uploads/products/'.$id)){
mkdir('../../../uploads/products/'.$id, 0777);
}
if(file_exists('../../../'.$featured100_full_path)) {
chmod('../../../'.$featured100_full_path, 0755);
unlink('../../../'.$featured100_full_path);
}
if(!move_uploaded_file($_FILES['image1']['tmp_name'], '../../../'.$featured100_full_path)){
echo 'Error: Image Not Uploaded!';
}
if($extension=="jpg" || $extension=="jpeg"){
$uploadedfile = $_FILES['image1']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
else if($extension=="png"){
$uploadedfile = $_FILES['image1']['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
} else {
$src = imagecreatefromgif($uploadedfile);}
list($width, $height) = getimagesize($filename);
$newwidth = 300;
$newheight = 300;
$featured300 = imagecreatetruecolor($newwidth, $newheight);
$newwidth1 = 150;
$newheight1 = 150;
$featuredthumb = imagecreatetruecolor($newwidth1, $newheight1);
imagecopyresampled($featured300,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
imagecopyresampled($featuredthumb,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
$filename_featured300 = 'uploads/products/'.$id.'/featured300.'.$extension;
$filename_featuredthumb = 'uploads/products/'.$id.'/featuredthumb.'.$extension;
imagejpeg($featured300, '../../../'.$filename_featured300,100);
imagejpeg($featuredthumb, '../../../'.$filename_featuredthumb,100);
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);