note 81272 deleted from function.imagecopyresampled by betz

From: Date: Wed, 20 Feb 2008 21:49:30 +0000
Subject: note 81272 deleted from function.imagecopyresampled by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-136329@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- This is a fixed version of ImageCopyResampledBicubic posted by liviu.malaescu The original version wasn't respecting src_x & src_y args <?php function ImageCopyResampledBicubic(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { // we should first cut the piece we are interested in from the source $src_img = ImageCreateTrueColor($src_w, $src_h); imagecopy($src_img, $src_image, 0, 0, $src_x, $src_y, $src_w, $src_h); // this one is used as temporary image $dst_img = ImageCreateTrueColor($dst_w, $dst_h); ImagePaletteCopy($dst_img, $src_img); $rX = $src_w / $dst_w; $rY = $src_h / $dst_h; $w = 0; for ($y = 0; $y < $dst_h; $y++) { $ow = $w; $w = round(($y + 1) * $rY); $t = 0; for ($x = 0; $x < $dst_w; $x++) { $r = $g = $b = 0; $a = 0; $ot = $t; $t = round(($x + 1) * $rX); for ($u = 0; $u < ($w - $ow); $u++) { for ($p = 0; $p < ($t - $ot); $p++) { $c = ImageColorsForIndex($src_img, ImageColorAt($src_img, $ot + $p, $ow + $u)); $r += $c['red']; $g += $c['green']; $b += $c['blue']; $a++; } } ImageSetPixel($dst_img, $x, $y, ImageColorClosest($dst_img, $r / $a, $g / $a, $b / $a)); } } // apply the temp image over the returned image and use the destination x,y coordinates imagecopy($dst_image, $dst_img, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h); // we should return true since ImageCopyResampled/ImageCopyResized do it return true; } ?>

« previous php.notes (#136329) next »