复制程式
<?php
function ImageResize (&$src, $x, $y) {
$dst=imagecreatetruecolor($x, $y);
$pals=ImageColorsTotal ($src);
for ($i=0; $i<$pals; $i++) {
$colors=ImageColorsForIndex ($src, $i);
ImageColorAllocate ($dst, $colors['red'], $colors['green'], $colors['blue']);
}
$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);
}
?>