如何在php中用虚线边框绘制一个圆圈?

问题描述:

我想画一个带有虚线边框的圆。 imagearc函数可以用于简单的边框。但我没有任何办法可以解决虚线边界问题。如何在php中用虚线边框绘制一个圆圈?

谢谢。

这里是画虚线circle.enjoy的

<?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; 
    } 
} 
?> 

多一个办法!

<?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

+0

两个代码并不会自动为我工作。 – Smart 2011-05-06 13:05:19

+0

你得到什么错误? – diEcho 2011-05-06 13:05:46

+0

尝试了第一个:'dashedcircle($ im,70,80,20,$ green,1);'但它只在cx和cy相同时才起作用。 http://viper-7.com/8zXkCK – Veda 2015-06-29 16:39:49

这里是我用来做什么的代码。

<?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); 
?> 
+0

我认为OP已经知道如何绘制一个圆,他想知道如何制作一个虚线的板 – Andre 2011-05-06 12:28:59

+0

通过交错角度创建一个虚线圆。看看迭代角度的for循环。 – 2011-05-06 12:32:45

+0

好吧,这工作正常。但是如果可能的话,我也想要抗锯齿和更改边框的粗细。 – Smart 2011-05-06 13:05:44