How to draw a circle with dashed border in php?
I want to draw a circle with dashed border. imagearc function can开发者_开发问答 be used for simple border. But I don't get any way for dashed border.
Thanks.
here it is
<?php
function dashedcircle($im, $cx, $cy, $radius, $colour, $dashsize=5) {
$dash=false;
for ($angle=0; $angle<=(180+$dashsize); $angle+=$dashsize) {
$x = ($radius * cos(deg2rad($angle)));
$y = ($radius * sin(deg2rad($angle)));
if ($dash) {
imageline($im, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
imageline($im, $cx-$px, $cx-$py, $cx-$x, $cy-$y, $colour);
}
$dash=!$dash;
$px=$x;
$py=$y;
}
}
?>
one more way of drawing a dashed-line circle.enjoy!
<?php
header("Content-type: image/jpeg");
$im = imagecreate(100,100);
$b = imagecolorallocate ($im, 0, 0, 0);
$w = imagecolorallocate ($im, 255, 255, 255);
$style = array ($b,$b,$b,$b,$b,$w,$w,$w,$w,$w);
imagesetstyle ($im, $style);
imagearc($im,50,50,100,100,0,360,IMG_COLOR_STYLED);
imagejpeg($im);
imagedestroy($im);
?>
Reference
Here is the code I used to do it.
<?php
$thick = 10;
// create a 200*200 image
$img = imagecreatetruecolor(200, 200);
// Add antialias
imageantialias ($img, true);
// allocate some colors
$white = imagecolorallocate($img, 255, 255, 255);
// draw the dashed circle
for($t = 1;$t<($thick+1);$t++) {
for($i = 0;$i<360;$i+=10) {
imagearc($img, 100, 100, 200-($t/5), 200-($t/5), $i, $i+5, $white);
imagearc($img, 100, 100, 200+($t/5), 200+($t/5), $i, $i+5, $white);
}
}
// output image in the browser
header("Content-type: image/png");
imagepng($img);
// free memory
imagedestroy($img);
?>
精彩评论