function image_imagemagick_roundedcorners in ImageCache Actions 8
Same name and namespace in other branches
- 7 canvasactions/rounded_corners.inc \image_imagemagick_roundedcorners()
imageapi_roundedcorners
File
- canvasactions/
rounded_corners.inc, line 273 - Routines for rounded corners
Code
function image_imagemagick_roundedcorners($image, $action) {
// Based on the imagemagick documentation.
// http://www.imagemagick.org/Usage/thumbnails/#rounded
// Create arc cut-outs, then mask them.
// Draw black triangles and white circles.
// draw circle is center: x,y, and a point on the perimeter
$corners = array(
'tl',
'tr',
'bl',
'br',
);
$radii = $action['independent_corners_set']['radii'];
$width = $image->info['width'];
$height = $image->info['height'];
$tl = $radii['tl'];
$tr = $radii['tr'];
$bl = $radii['bl'];
$br = $radii['br'];
$drawmask = '';
if ($tl) {
$drawmask .= " fill black polygon 0,0 0,{$tl} {$tl},0";
$drawmask .= " fill white circle {$tl},{$tl} {$tl},0";
}
if ($tr) {
$right = $width - $tr;
$drawmask .= " fill black polygon {$right},0 {$width},0 {$width},{$tr}";
$drawmask .= " fill white circle {$right},{$tr} {$right},0";
}
if ($bl) {
$bottom = $height - $bl;
$drawmask .= " fill black polygon 0,{$bottom} 0,{$height} {$bl},{$height}";
$drawmask .= " fill white circle {$bl},{$bottom} 0,{$bottom}";
}
if ($br) {
$bottom = $height - $br;
$right = $width - $br;
$drawmask .= " fill black polygon {$right},{$height} {$width},{$bottom} {$width},{$height}";
$drawmask .= " fill white circle {$right},{$bottom} {$width},{$bottom}";
}
$draw = ' -draw ' . escapeshellarg($drawmask);
$compose = ' ' . escapeshellcmd('(') . " +clone -threshold -1 {$draw} " . escapeshellcmd(')') . ' +matte -compose CopyOpacity -composite ';
$image->ops[] = $compose;
return TRUE;
}