note 81272 added to function.imagecopyresampled
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 20 Feb 2008 21:16:03 +0000 |
| Subject: | note 81272 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136324@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 89.190.194.18
Probable Submitter: 195.149.249.253
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- https://master.php.net/note/edit/81272
Del: integrated -- https://master.php.net/note/delete/81272/integrated
Del: useless -- https://master.php.net/note/delete/81272/useless
Del: bad code -- https://master.php.net/note/delete/81272/bad+code
Del: spam -- https://master.php.net/note/delete/81272/spam
Del: non-english -- https://master.php.net/note/delete/81272/non-english
Del: in docs -- https://master.php.net/note/delete/81272/in+docs
Del: other reasons-- https://master.php.net/note/delete/81272
Reject -- https://master.php.net/note/reject/81272
Search -- https://master.php.net/manage/user-notes.php