note 39985 deleted from function.imagecopyresized by aidan
| From: | aidan@php.net | Date: | Mon, 04 Oct 2004 09:38:26 +0000 |
| Subject: | note 39985 deleted from function.imagecopyresized by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77904@lists.php.net to get a copy of this message | ||
Note Submitter: sergei at gmx dot net
----
Here's slightly faster ImageCopyResampleBicubic function. I'm using intval() instead of
round() which makes it 5%-10% faster:
<?
function ImageCopyResampleBicubic (&$dimg, &$simg, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh) {
ImagePaletteCopy ($dimg, $simg);
$rX = $sw / $dw;
$rY = $sh / $dh;
$nY = 0;
for ($y=$dy; $y<$dh; $y++) {
$oY = $nY;
$nY = intval(($y + 1) * $rY+.5);
$nX = 0;
for ($x=$dx; $x<$dw; $x++) {
$r = $g = $b = $a = 0;
$oX = $nX;
$nX = intval(($x + 1) * $rX+.5);
for ($i=$nY; --$i>=$oY;) {
for ($j=$nX; --$j>=$oX;) {
$c = ImageColorsForIndex ($simg, ImageColorAt ($simg, $j, $i));
$r += $c['red'];
$g += $c['green'];
$b += $c['blue'];
$a++;
}
}
ImageSetPixel ($dimg, $x, $y, ImageColorClosest ($dimg, $r/$a, $g/$a, $b/$a));
}
}
}
?>