note 33645 added to function.imagecopyresampled
| From: | mark at trilab dot ch | Date: | Wed, 02 Jul 2003 21:21:28 +0000 |
| Subject: | note 33645 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51385@lists.php.net to get a copy of this message | ||
// 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));
}
}
}
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33645
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33645&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33645&report=yes