note 80417 added to function.imagecopyresampled
| From: | MichaelShepanski at osu1 dot php dot net | Date: | Tue, 15 Jan 2008 06:09:17 +0000 |
| Subject: | note 80417 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135107@lists.php.net to get a copy of this message | ||
Here is a function I thought I would share that will resample and copy an image with rounded
corners.
<?php
/** ------------------------------------------------------------
* Copy and resample an image with rounded corners.
* ----------------------------------------------------------- */
function imageRoundedCopyResampled(&$dstimg, &$srcimg, $dstx, $dsty, $srcx,
$srcy, $dstw, $dsth, $srcw, $srch, $radius) {
# Resize the Source Image
$srcResized = imagecreatetruecolor($dstw, $dsth);
imagecopyresampled($srcResized, $srcimg, 0, 0, $srcx, $srcy,
$dstw, $dsth, $srcw, $srch);
# Copy the Body without corners
imagecopy($dstimg, $srcResized, $dstx+$radius, $dsty,
$radius, 0, $dstw-($radius*2), $dsth);
imagecopy($dstimg, $srcResized, $dstx, $dsty+$radius,
0, $radius, $dstw, $dsth-($radius*2));
# Create a list of iterations; array(array(X1, X2, CenterX, CenterY), ...)
# Iterations in order are: Top-Left, Top-Right, Bottom-Left, Bottom-Right
$iterations = array(
array(0, 0, $radius, $radius),
array($dstw-$radius, 0, $dstw-$radius, $radius),
array(0, $dsth-$radius, $radius, $dsth-$radius),
array($dstw-$radius, $dsth-$radius, $dstw-$radius, $dsth-$radius)
);
# Loop through each corner 'iteration'
foreach($iterations as $iteration) {
list($x1,$y1,$cx,$cy) = $iteration;
for ($y=$y1; $y<=$y1+$radius; $y++) {
for ($x=$x1; $x<=$x1+$radius; $x++) {
# If length (X,Y)->(CX,CY) is less then radius draw the point
$length = sqrt(pow(($cx - $x), 2) + pow(($cy - $y), 2));
if ($length < $radius) {
imagecopy($dstimg, $srcResized, $x+$dstx, $y+$dsty,
$x, $y, 1, 1);
}
}
}
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.232.58.58
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- https://master.php.net/note/edit/80417
Del: integrated -- https://master.php.net/note/delete/80417/integrated
Del: useless -- https://master.php.net/note/delete/80417/useless
Del: bad code -- https://master.php.net/note/delete/80417/bad+code
Del: spam -- https://master.php.net/note/delete/80417/spam
Del: non-english -- https://master.php.net/note/delete/80417/non-english
Del: in docs -- https://master.php.net/note/delete/80417/in+docs
Del: other reasons-- https://master.php.net/note/delete/80417
Reject -- https://master.php.net/note/reject/80417
Search -- https://master.php.net/manage/user-notes.php