= 0) { // Get the transparent color from the original image $trnprt_color = imagecolorsforindex($image, $trnprt_indx); // Allocate the same color in the new image $trnprt_indx = imagecolorallocate($resizedImage, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']); imagefill($resizedImage, 0, 0, $trnprt_indx); imagecolortransparent($resizedImage, $trnprt_indx); } } imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); $success = false; switch ($mimeType) { case 'image/jpeg': $success = imagejpeg($resizedImage, $imagePath, 90); // 90% quality break; case 'image/png': $success = imagepng($resizedImage, $imagePath); break; case 'image/gif': $success = imagegif($resizedImage, $imagePath); break; } imagedestroy($image); imagedestroy($resizedImage); return $success; } }