note 24424 deleted from function.imagecopyresized by cece

From: Date: Sat, 16 Aug 2003 20:05:34 +0000
Subject: note 24424 deleted from function.imagecopyresized by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54446@lists.php.net to get a copy of this message
Note Submitter: info@free-dev.com ---- Other derived function from the great ImageCopyResampleBicubic(), in PHP. Most people just need to resize his pictures, so I wrote a more simple function to resize a picture with the less $vars as possible... if somebody can make my function faster... <? ######## just a sample how to use ######## $b=imagecreatefrompng ("max.png"); # i get my source picture $bx=imagesx ($b); #source width $by=imagesy ($b); # source height $my=450; # new img height $mx=intval($my*$bx/$by); # new img width # note, it's the same ratio h/w $m=ImageResize ($b, $mx, $my); # the function generates a new image, you just need to send it in a $var imagepng ($m); # i show you my new picture ######## the function ######## function ImageResize (&$src, $x, $y) { /* Function derived from ImageCopyResampleBicubic() Original code in C, for the PHP GD Module by jernberg@fairytale.se Port to PHP by John Jensen July 10 2001 Updated by tim@smoothdeity.com Re-edited & optimized by TCK */ $dst=ImageCreate ($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); } ?>

« previous php.notes (#54446) next »