note 39985 added to function.imagecopyresized
| From: | sergei at gmx dot net | Date: | Tue, 17 Feb 2004 17:57:31 +0000 |
| Subject: | note 39985 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65312@lists.php.net to get a copy of this message | ||
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));
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39985
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39985&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39985&report=yes
Search -- http://master.php.net/manage/user-notes.php