function imageapi_imagemagick_image_roundedcorners in ImageCache Actions 6
Same name and namespace in other branches
- 6.2 canvasactions/rounded_corners.inc \imageapi_imagemagick_image_roundedcorners()
imageapi_roundedcorners
File
- ./
canvasactions.inc, line 855 - Helper functions for the text2canvas action for imagecache
Code
function imageapi_imagemagick_image_roundedcorners(&$image, $action = array()) {
// 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 = " -draw '";
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} ";
}
$drawmask .= " ' ";
$compose = " \\( +clone -threshold -1 {$drawmask} \\) +matte -compose CopyOpacity -composite ";
$image->ops[] = $compose;
return TRUE;
}