$maxWidth){ $newWidth = $maxWidth; $newHeight = floor(($height*$maxWidth)/$width); } else { $newHeight = $maxHeight; $newWidth = floor(($width*$maxHeight)/$height); } //Create reduced image $dest = imagecreatetruecolor($newWidth, $newHeight); //Copy image imagecopyresized($dest, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); //Try to export image //PNG if($outFormat === "image/png"){ if(!imagepng($dest, $targetFile, 2)) return false; } //JPEG elseif($outFormat === "image/jpeg"){ if(!imagejpeg($dest, $targetFile, 2)) return false; } //UNSUPORTED else return false; //Unkown export format //Success return true; }