如何在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);
?>
答
这里是我用来做什么的代码。
<?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);
?>
两个代码并不会自动为我工作。 – Smart 2011-05-06 13:05:19
你得到什么错误? – diEcho 2011-05-06 13:05:46
尝试了第一个:'dashedcircle($ im,70,80,20,$ green,1);'但它只在cx和cy相同时才起作用。 http://viper-7.com/8zXkCK – Veda 2015-06-29 16:39:49