I have error in this code:
copy($newFile,$target_dir.'slider_'.$newName);
$file2 = $target_dir.'slider_'.$newName; //This is the original file
list($width2, $height2) = $newFile;
$modwidth2 = 750;
$modheight2 = 300;
$tn2 = imagecreatetruecolor($modwidth2, $modheight2);
if ($imageFileType == "jpg"){
$image2 = imagecreatefromjpeg($newFile);
imagecopyresampled($tn2, $image2, 0, 0, 0, 0, $modwidth2, $modheight2, $width2, $height2);
imagejpeg($tn2, $file2, 50);
} elseif ($imageFileType == "png"){
imagealphablending($tn2, false);
imagesavealpha($tn2, true);
$image2 = imagecreatefrompng($newFile);
imagecopyresampled($tn2, $image2, 0, 0, 0, 0, $modwidth2, $modheight2, $width2, $height2);
imagepng($tn2, $file2, 9);
} elseif ($imageFileType == "jpeg"){
$image2 = imagecreatefromjpeg($newFile);
imagecopyresampled($tn2, $image2, 0, 0, 0, 0, $modwidth2, $modheight2, $width2, $height2);
imagejpeg($tn2, $file2, 9);
}
If i upload a photo, output always blank black. Can u tell me what is wrong in this code ?
you are not getting width & height properly.
list($width2, $height2) = $newFile;
change to
list($width2, $height2) = getimagesize ($newFile)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.