note 77679 added to function.imagecopyresampled
| From: | timatleethostdotcom at osu1 dot php dot net | Date: | Sat, 08 Sep 2007 04:25:23 +0000 |
| Subject: | note 77679 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130309@lists.php.net to get a copy of this message | ||
Here's an improved and corrected version of my fastimagecopyresampled script. Because I
typically scale entire images it appears my previous code was not properly tested. In any case,
this new script has been thoroughly tested, cleaned up, and enhanced. The code is a little tighter
and quality values between 0 and 1 will yield a mosaic effect (basically lowering quality below the
pervious lowest value of 1). I would still suggest using a quality of 2 to 4 as that's the
primary purpose of this script, which is high quality and fast results. Don't be afraid of
using a quality value of 1.5 for extreme cases where you have a bunch of very large images from
digital cameras (like those 10M pixel cameras theses days) and creating thumbnails in batch mode.
Even a quality of 1.5 is a big improvement over imagecopyresized and is ultra-fast.
Anyway, enjoy and I hope this is the bug-free last version.
<?
function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y,
$dst_w, $dst_h, $src_w, $src_h, $quality = 3) {
// Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.
// Just include this function and change all "imagecopyresampled" references to
"fastimagecopyresampled".
// Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail
size using the default quality setting.
// Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely
distributable - These comments must remain.
//
// Optional "quality" parameter (defaults is 3). Fractional values are allowed, for
example 1.5. Must be greater than zero.
// Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect.
// 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized.
// 2 = Up to 95 times faster. Images appear a little sharp, some prefer this over a quality of 3.
// 3 = Up to 60 times faster. Will give high quality smooth results very close to
imagecopyresampled, just faster.
// 4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images.
// 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled.
if (empty($src_image) || empty($dst_image) || $quality <= 0) { return false; }
if ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) <
$src_h)) {
$temp = imagecreatetruecolor ($dst_w * $quality + 1, $dst_h * $quality + 1);
imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h *
$quality + 1, $src_w, $src_h);
imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality,
$dst_h * $quality);
imagedestroy ($temp);
} else imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h,
$src_w, $src_h);
return true;
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 72.240.221.30
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- https://master.php.net/note/edit/77679
Del: integrated -- https://master.php.net/note/delete/77679/integrated
Del: useless -- https://master.php.net/note/delete/77679/useless
Del: bad code -- https://master.php.net/note/delete/77679/bad+code
Del: spam -- https://master.php.net/note/delete/77679/spam
Del: non-english -- https://master.php.net/note/delete/77679/non-english
Del: in docs -- https://master.php.net/note/delete/77679/in+docs
Del: other reasons-- https://master.php.net/note/delete/77679
Reject -- https://master.php.net/note/reject/77679
Search -- https://master.php.net/manage/user-notes.php