note 86818 added to function.imagecopyresampled
| From: | tim at leethost dot com | Date: | Wed, 05 Nov 2008 03:40:52 +0000 |
| Subject: | note 86818 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146149@lists.php.net to get a copy of this message | ||
<?php
function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y,
$dst_w, $dst_h, $src_w, $src_h, $quality=2.33) {
// Author: Tim Eckel - Date: 11/04/08 - Version: 1.2 - Project: FreeRingers.net - Freely
distributable - These comments must remain.
// 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.
//
// New in v1.2: 2 to 5 times faster when enlarging (v1.1 was slower than default
imagecopyresampled when enlarging).
// New in v1.2: Never slower than default imagecopyresampled function (v1.1 could be slower than
default imagecopyresampled).
// New in v1.2: Default quality of 2.33 reduces sizing artifacts that could happen with v1.1
(highly suggested: don't change this value).
// New in v1.2: Automatically selects proper method to scale image for best quality and highest
speed.
if (empty($src_image) || empty($dst_image) || $quality < 1) { return false; }
$scale = ($src_w / $dst_w + $src_h / $dst_h) / 2;
if ($dst_w == $src_w && $dst_h == $src_h) imagecopy ($dst_image, $src_image, 0, 0, 0, 0,
$dst_w, $dst_h);
elseif ($scale >= $quality) { $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); }
elseif ($scale == 1) imagecopyresized ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y,
$dst_w + 1, $dst_h + 1, $src_w, $src_h);
elseif ($scale > 1 / $quality) imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y,
$src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
else { $temp = imagecreatetruecolor ($src_w * $quality, $src_h * $quality);
imagecopyresampled ($temp, $src_image, 0, 0, $src_x, $src_y, $src_w * $quality, $src_h *
$quality, $src_w, $src_h);
imagecopyresized ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w + 1, $dst_h + 1, $src_w *
$quality, $src_h * $quality);
imagedestroy ($temp); }
return true;
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 72.240.237.20
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- https://master.php.net/note/edit/86818
Del: integrated -- https://master.php.net/note/delete/86818/integrated
Del: useless -- https://master.php.net/note/delete/86818/useless
Del: bad code -- https://master.php.net/note/delete/86818/bad+code
Del: spam -- https://master.php.net/note/delete/86818/spam
Del: non-english -- https://master.php.net/note/delete/86818/non-english
Del: in docs -- https://master.php.net/note/delete/86818/in+docs
Del: other reasons-- https://master.php.net/note/delete/86818
Reject -- https://master.php.net/note/reject/86818
Search -- https://master.php.net/manage/user-notes.php