note 36344 added to function.imagecopyresized
| From: | f dot s at gmx dot com | Date: | Mon, 06 Oct 2003 17:31:27 +0000 |
| Subject: | note 36344 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57905@lists.php.net to get a copy of this message | ||
Here's a 10 to 30 percent faster version of ImageCopyResampleBicubic from Daniel.
Very good quality, but still very slow.
<?
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 = round(($y + 1) * $rY);
$nX = 0;
for ($x=$dx; $x<$dw; $x++) {
$oX = $nX;
$nX = round(($x + 1) * $rX);
$r = $g = $b = $a = 0;
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+36344
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36344&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36344&report=yes
Search -- http://master.php.net/manage/user-notes.php