note 13940 deleted from function.imagecopyresized by aidan
| From: | aidan@php.net | Date: | Mon, 04 Oct 2004 09:40:46 +0000 |
| Subject: | note 13940 deleted from function.imagecopyresized by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77930@lists.php.net to get a copy of this message | ||
Note Submitter: rze at counter-strike dot net
----
For those who can't update their GD modules, I've made this function. If you think you can
make any good changes, feel free to e-mail them to me.
Frankly I have no idea what the for loop in the first example does, I just guessed and it seems to
work fine.
Note: it's a VERY, VERY, VERY slow function. Never use it for dynamic output, only saving to a
thumbnail file or the like.
function ImageCopyResampleBicubic ($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w,
$dst_h, $src_w, $src_h)
/*
port to PHP by John Jensen July 10 2001 -- original code (in C, for the PHP GD Module) by
jernberg@fairytale.se
*/
{
for ($i = 0; $i < 256; $i++) { // get pallete. Is this algoritm correct?
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'],
$colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = $scaleX / 2.0;
$scaleY2 = $scaleY / 2.0;
for ($j = $src_y; $j < $dst_h; $j++) {
$sY = $j * $scaleY;
for ($i = $src_x; $i < $dst_w; $i++) {
$sX = $i * $scaleX;
$c1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY + $scaleY2));
$c2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX, (int) $sY));
$c3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY +
$scaleY2));
$c4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY));
$red = (int) (($c1['red'] + $c2['red'] + $c3['red'] +
$c4['red']) / 4);
$green = (int) (($c1['green'] + $c2['green'] + $c3['green'] +
$c4['green']) / 4);
$blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] +
$c4['blue']) / 4);
$color = ImageColorClosest ($dst_img, $red, $green, $blue);
ImageSetPixel ($dst_img, $i + $dst_x, $j + $dst_y, $color);
}
}
}