2011-05-06 135 views

回答

2

這裏是畫虛線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

1

這裏是我用來做什麼的代碼。

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