note 24426 deleted from function.imagecopyresized by aidan
| From: | aidan@php.net | Date: | Mon, 04 Oct 2004 09:40:29 +0000 |
| Subject: | note 24426 deleted from function.imagecopyresized by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77925@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Ooops, my first optimization : id didn't work with alpha before... here is a solution witch
supports apla blending but I'm not sure it's the best method : I copy my color index
(including alpha) and that's all my changes (notice that the code is smaller...)
<?
function imageresize (&$src, $x, $y) {
$dst=ImageCreate ($x, $y);
#########################
ImagePaletteCopy ($dst,$src);
#########################
$scX =(imagesx ($src)-1)/$x;
$scY =(imagesy ($src)-1)/$y;
$scX2 =intval($scX/2);
$scY2 =intval($scY/2);
for ($j = 0; $j < ($y); $j++) {
$sY = intval($j * $scY);
$y13 = $sY + $scY2;
for ($i = 0; $i < ($x); $i++) {
$sX = intval($i * $scX);
$x34 = $sX + $scX2;
$c1 = ImageColorsForIndex ($src, ImageColorAt ($src, $sX, $y13));
$c2 = ImageColorsForIndex ($src, ImageColorAt ($src, $sX, $sY));
$c3 = ImageColorsForIndex ($src, ImageColorAt ($src, $x34, $y13));
$c4 = ImageColorsForIndex ($src, ImageColorAt ($src, $x34, $sY));
$r = ($c1['red']+$c2['red']+$c3['red']+$c4['red'])/4;
$g =
($c1['green']+$c2['green']+$c3['green']+$c4['green'])/4;
$b =
($c1['blue']+$c2['blue']+$c3['blue']+$c4['blue'])/4;
ImageSetPixel ($dst, $i, $j, ImageColorClosest ($dst, $r, $g, $b));
}
}
return ($dst);
}
>?