note 58545 deleted from function.imagecopyresampled by cmb

From: Date: Sun, 19 May 2019 16:12:38 +0000
Subject: note 58545 deleted from function.imagecopyresampled by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211081@lists.php.net to get a copy of this message
Note Submitter: George_A ---- For the best image quality... How to get new proportional size of the image if the desible size of source image is approximatly equal to needed size. If needed size differs from source size on less than the user factor then transformation isn`t apply. /**********************************************/ function imageCopyResize($image, $xSize, $ySize, $needed_user_factor, $new_image_path = "") { //example: neded_user_factor = 0.2 if($xSize == 0 || $ySize == 0) return array("At the leat one pair of size is 0",0,0); $size = getImageSize($image); $width = $size[0]; $height = $size[1]; $x_ratio = $xSize / $size[0]; $y_ratio = $ySize / $size[1]; if($x_ratio > $y_ratio) $res_ratio = $y_ratio; else $res_ratio = $x_ratio; if(abs($res_ratio - 1) > $needed_user_factor) { $width = ceil($width * $res_ratio); $height = ceil($height * $res_ratio); } $fileinfo = pathinfo($image); $file_type = strtolower($fileinfo["extension"]); if($file_type == "jpg" || $file_type == "jpeg") $src = ImageCreateFromJpeg($image); else if($file_type == "gif") $src = ImageCreateFromGif($image); else if($file_type == "png") $src = ImageCreateFromPNG($image); else if($file_type == "bmp") $src = ImageCreateFromBmp($image); //Thanks Previous Coder else return array("Unknown image format: ".$file_type, 0, 0); $output_path = ($new_image_path == "")?$image:$new_image_path; $dst = ImageCreateTrueColor($width, $height); ImageCopyResized($dst, $src, 0,0,0,0,$width, $height, $size[0], $size[1]); if($file_type == "jpg" || $file_type == "jpeg") ImageJpeg($dst, $output_path, 100); else if($file_type == "gif" || $file_type == "bmp") ImageGif($dst, $output_path); else if($file_type == "png") ImagePNG($dst, $output_path); ImageDestroy($src); ImageDestroy($dst); return array("", $width, $height); } /**********************************************/

« previous php.notes (#211081) next »