note 43413 deleted from function.imagecopyresampled by aidan

From: Date: Mon, 04 Oct 2004 09:42:29 +0000
Subject: note 43413 deleted from function.imagecopyresampled by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77938@lists.php.net to get a copy of this message
Note Submitter: sirsiggi at bin-ich-jesus dot de ---- Here's a very easy to use and very versatile resizing-function that produces a good quality and is quite fast. function imageresize($img,$target="",$width=0,$height=0,$percent=0){ // create an image of the given filetype if (strpos($img,".jpg") !== false or strpos($img,".jpeg") !== false) { $image = ImageCreateFromJpeg($img); $extension = ".jpg"; } elseif (strpos($img,".png") !== false) { $image = ImageCreateFromPng($img); $extension = ".png"; } elseif (strpos($img,".gif") !== false) { $image = ImageCreateFromGif($img); $extension = ".gif"; } $size = getimagesize ($img); // calculate missing values if ($width and !$height) { $height = ($size[1] / $size[0]) * $width; } elseif (!$width and $height) { $width = ($size[0] / $size[1]) * $height; } elseif ($percent) { $width = $size[0] / 100 * $percent; $height = $size[1] / 100 * $percent; } elseif (!$width and !$height and !$percent) { $width = 100; // here you can enter a standard value for actions where no arguments are given $height = ($size[1] / $size[0]) * $width; } $thumb = imagecreatetruecolor ($width, $height); if (function_exists("imageCopyResampled")) { if (!@ImageCopyResampled($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1])) { ImageCopyResized($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); } } else { ImageCopyResized($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); } //ImageCopyResampleBicubic ($thumb, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); if (!$target) { $target = "temp".$extension; } $return = true; switch ($extension) { case ".jpg": { imagejpeg($thumb, $target, 70); break; } case ".gif": { imagegif($thumb, $target); break; } case ".png": { imagepng($thumb, $target); break; } default: { $return = false; } } // report the success (or fail) of the action return $return; }

« previous php.notes (#77938) next »