note 33645 deleted from function.imagecopyresampled by aidan
| From: | aidan@php.net | Date: | Mon, 04 Oct 2004 09:44:34 +0000 |
| Subject: | note 33645 deleted from function.imagecopyresampled by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77958@lists.php.net to get a copy of this message | ||
Note Submitter: mark at trilab dot ch
----
// another enlargment function
// uses interpolation for very smooth results (slow but good)
// truecolor only
function imagecopyenlarged($dst_img, $src_img, $dst_x, $dst_y,$src_x, $src_y, $dst_w, $dst_h,
$src_w, $src_h)
{
set_time_limit(0);
$scale_x = $src_w / $dst_w;
$scale_y = $src_h / $dst_h;
$srcmax_x = imagesx($src_img) - 1;
$srcmax_y = imagesy($src_img) - 1;
$dstmax_x = imagesx($dst_img) - 1;
$dstmax_y = imagesy($dst_img) - 1;
$dx0 = max(0, -$dst_x);
$dy0 = max(0, -$dst_y);
$dx1 = min($dst_w, 1 + $dstmax_x - $dst_x);
$dy1 = min($dst_h, 1 + $dstmax_y - $dst_y);
for ($y = $dy0; $y < $dy1; $y++)
{
$sy = ($y + 0.5)*$scale_y + $src_y - 0.5;
$qy1 = $sy - floor($sy);
$qy0 = 1.0 - $qy1;
$y0 = max(0, min($srcmax_y, floor($sy)));
$y1 = max(0, min($srcmax_y, floor($sy) + 1));
for ($x = $dx0; $x < $dx1; $x++)
{
$sx = ($x + 0.5)*$scale_x + $src_x - 0.5;
$qx1 = $sx - floor($sx);
$qx0 = 1.0 - $qx1;
$x0 = max(0, min($srcmax_x, floor($sx)));
$x1 = max(0, min($srcmax_x, floor($sx) + 1));
// left upper
$rgb = imagecolorat($src_img, $x0, $y0);
$f = $qx0*$qy0;
$cr = $f*(($rgb >> 16) & 0xFF);
$cg = $f*(($rgb >> 8) & 0xFF);
$cb = $f*($rgb & 0xFF);
// right upper
$rgb = imagecolorat($src_img, $x1, $y0);
$f = $qx1*$qy0;
$cr += $f*(($rgb >> 16) & 0xFF);
$cg += $f*(($rgb >> 8) & 0xFF);
$cb += $f*($rgb & 0xFF);
// left lower
$rgb = imagecolorat($src_img, $x0, $y1);
$f = $qx0*$qy1;
$cr += $f*(($rgb >> 16) & 0xFF);
$cg += $f*(($rgb >> 8) & 0xFF);
$cb += $f*($rgb & 0xFF);
// right lower
$rgb = imagecolorat($src_img, $x1, $y1);
$f = $qx1*$qy1;
$cr += $f*(($rgb >> 16) & 0xFF);
$cg += $f*(($rgb >> 8) & 0xFF);
$cb += $f*($rgb & 0xFF);
//mixed
imagesetpixel($dst_img, $x + $dst_x, $y + $dst_y, ((floor($cr) & 0xFF) << 16) |
((floor($cg) & 0xFF) << 8) | (floor($cb) & 0xFF));
}
}
}