note 24426 added to function.imagecopyresized
| From: | php-general at lists dot php dot net | Date: | Thu, 15 Aug 2002 19:29:31 +0000 |
| Subject: | note 24426 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35086@lists.php.net to get a copy of this message | ||
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);
}
>?
--
http://www.php.net/manual/en/function.imagecopyresized.php
http://master.php.net/manage/user-notes.php?action=edit+24426
http://master.php.net/manage/user-notes.php?action=delete+24426
http://master.php.net/manage/user-notes.php?action=reject+24426