note 33244 added to function.imagecopyresized
| From: | daniel dot stankewitz at onvista dot de | Date: | Thu, 19 Jun 2003 23:01:41 +0000 |
| Subject: | note 33244 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50688@lists.php.net to get a copy of this message | ||
Hi, today it took me some hours to figure out this function. This one seems to be _really_ bicubic,
because it calculates the rectangles of the src image fitting to one pixel of the dst image and
averages them. The Quality is much better than the function with the same name above, but
unfortunately its twice or triple as slow. :-( Maybe someone can enhance / tune it. Would be cool.
It's still not usable for thumbnail lists.
--Daniel
function ImageCopyResampleBicubic (&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y,
$dst_w, $dst_h, $src_w, $src_h) {
ImagePaletteCopy ($dst_img, $src_img);
$rX = $src_w / $dst_w;
$rY = $src_h / $dst_h;
$w = 0;
for ($y = $dst_y; $y < $dst_h; $y++) {
$ow = $w; $w = round(($y + 1) * $rY);
$t = 0;
for ($x = $dst_x; $x < $dst_w; $x++) {
$r = $g = $b = 0; $a = 0;
$ot = $t; $t = round(($x + 1) * $rX);
for ($u = 0; $u < ($w - $ow); $u++) {
for ($p = 0; $p < ($t - $ot); $p++) {
$c = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $ot + $p, $ow + $u));
$r += $c['red'];
$g += $c['green'];
$b += $c['blue'];
$a++;
}
}
ImageSetPixel ($dst_img, $x, $y, ImageColorClosest ($dst_img, $r / $a, $g / $a, $b / $a));
}
}
}
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33244
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33244&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33244&report=yes