I am uploading a file image. I compress it to a specified width and height, but it always shows a blank image when I attempt to display a PNG, but it WILL display jpg or jpeg files.
function compress($extention, $destination, $quality, $tmpsource)
{
$extention = strtolower($extention);
list($width, $height) = getimagesize($destination);
$y = (800 * $height / $width);
$getType = null;
if ($extention == "jpeg") {
$source = imagecreatefromjpeg($destination);
}
if ($extention == "jpg") {
$source = imagecreatefromjpeg($destination);
}
if ($extention == "png") {
$source = imagecreatefrompng($destination);
}
$thumb = imagecreatetruecolor(800, $y);
imagecopyresized($thumb, $source, 0, 0, 0, 0, 800, $y, $width, $height);
if ($extention == "jpeg") {
imagejpeg($thumb, $destination, $quality);
}
if ($extention == "jpg") {
imagejpeg($thumb, $destination, $quality);
}
if ($extention == "png") {
imagepng($thumb, $destination, $quality);
}
return $destination;
}
Here is where I call it:
if (in_array($imgTypeArr[$i], $allowedTypes))
{
$newImgName = uniqid($newUniqName . "_") . "." . $getExt;
$imgUploadArr[] = $newImgName;
$destination = "../images/products/" . $proFolder . "/" . $newImgName;
move_uploaded_file($imgTmpArr[$i], $destination);
compress($getExt, $destination, 100);
}