note 120217 added to ref.image

From: Date: Thu, 24 Nov 2016 05:44:17 +0000
Subject: note 120217 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-207544@lists.php.net to get a copy of this message
This is an example of get high resolution images. <?php /** * Class name : resizeImage * Created by : wang * Description : This class is to resize the image from original size to new size */ class resizeImage { /** * Function name : resize_img * Description : This function is to resize image * @param : $origimg variable is the original image * @param : $newimg variable is the new image * @param : $w variable is the width of image * @param : $f variable is the height of image */ public function resize_img($origimg,$newimg,$w,$h){ $info = getimagesize($origimg); $mime = $info['mime']; // Make sure that the requested file is actually an image if(substr($mime, 0, 6) != 'image/') { header('HTTP/1.1 400 Bad Request'); return 'Error: requested file is not an accepted type: ' .$origimg; exit(); } // Check they extention of image $extension = image_type_to_extension($info[2]); if(strtolower($extension) == '.png'){ $img = $this->resize_imagepng($origimg,$w, $h); imagepng($img,$newimg); imagedestroy($img); }elseif(strtolower($extension) == '.jpeg'){ $img = $this->resize_imagejpeg($origimg, $w, $h); imagejpeg($img, $newimg); imagedestroy($img); }elseif(strtolower($extension == '.gif')){ $img = $this->resize_imagegif($origimg, $w, $h); imagegif($img,$newimg); imagedestroy($img); } } /** * End function name : resize_img */ /** * Function name : resize_imagepng * Description : This function is to resize png image * @param : $file variable is the original image * @param : $w variable is the width of image * @param : $f variable is the height of image */ private function resize_imagepng($file, $w, $h) { list($width, $height) = getimagesize($file); $src = imagecreatefrompng($file); $dst = imagecreatetruecolor($w, $h); imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height); return $dst; } /** * End function name : resize_imagepng */ /** * Function name : resize_imagejpeg * Description : This function is to resize jpeg image * @param : $file variable is the original image * @param : $w variable is the width of image * @param : $f variable is the height of image */ private function resize_imagejpeg($file, $w, $h) { list($width, $height) = getimagesize($file); $src = imagecreatefromjpeg($file); $dst = imagecreatetruecolor($w, $h); imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height); return $dst; } /** * End function name : resize_imagejpeg */ /** * Function name : resize_imagegif * Description : This function is to resize gif image * @param : $file variable is the original image * @param : $w variable is the width of image * @param : $f variable is the height of image */ private function resize_imagegif($file, $w, $h) { list($width, $height) = getimagesize($file); $src = imagecreatefromgif($file); $dst = imagecreatetruecolor($w, $h); imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height); return $dst; } /** * End function name : resize_imagegif */ } /** * End class name : resizeImage */ ?> ---- Server IP: 72.52.91.14 Probable Submitter: 43.226.7.178 ---- Manual Page -- http://php.net/manual/en/ref.image.php Edit -- https://master.php.net/note/edit/120217 Del: integrated -- https://master.php.net/note/delete/120217/integrated Del: useless -- https://master.php.net/note/delete/120217/useless Del: bad code -- https://master.php.net/note/delete/120217/bad+code Del: spam -- https://master.php.net/note/delete/120217/spam Del: non-english -- https://master.php.net/note/delete/120217/non-english Del: in docs -- https://master.php.net/note/delete/120217/in+docs Del: other reasons-- https://master.php.net/note/delete/120217 Reject -- https://master.php.net/note/reject/120217 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#207544) next »