Voting

: max(zero, one)?
(Example: nine)

The Note You're Voting On

Michael Shepanski
17 years ago
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);
}
}
}
}
}
?>

<< Back to user notes page

To Top