imagearc() - gd函数(图像处理)
imagearc()
(PHP 4, PHP 5, PHP 7)
画椭圆弧
说明
imagearc (resource $image,int $cx,int $cy,int $w,int $h,int $s,int $e,int $color) : boolimagearc() 以$cx,$cy(图像左上角为 0, 0)为中心在$image所代表的图像中画一个椭圆弧。$w和$h分别指定了椭圆的宽度和高度,起始和结束点以$s和$e参数以角度指定。0°位于三点钟位置,以顺时针方向绘画。
用 imagearc() 画一个圆
参见 imageellipse(),imagefilledellipse() 和 imagefilledarc()。
This is an example script I wrote for myself to help me learn how to used the imagearc functions. Maybe if will also help others.
The imagearc function has a precision of one degree. The function truncates the $start and $end values to the inferior degree. For example if the starting angle you calculated is : -178.62450462172° and the ending angle is : -152.78056427917° imagearc will draw a curve from -178° to -152°. If you need accurate curves drawing, you need to use a loop to draw little step-by-step lines. By creating a large number of short enough lines, you will create the impression of a curve with accuracy.
A previous for the Rotated (Filled)Ellipse note from(nojer2 at yahoo dot com, 02-Apr-2001 12:06) has a mistake, at the second arc. Replace them with the following listing. if ($filled) { triangle($im, $cx, $cy, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour); triangle($im, $cx, $cy, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour); } else { imageline($im, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour); imageline($im, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour); }
Please note that in order to draw a complete circle or ellipse (without using the imageellipse) you mustn't use 0 for both s and e. If you do this you will get, umm, nothing. Instead set s to 0 and e to 360 to get a complete circle or ellipse.
I needed an arc with a thick border and i didn't like to use 359.9 as end angle so i made a function that works pretty well:
Right... possibly the easiest way of drawing a filled circle: Loop through the imagearc function incrementing the diameter by one pixel: This works great for circles with diameters up to about 60 or 70 pixels wide. After that, you start to get pixle gaps.
imagesetstyle() sets the style to be used by all line drawing functions when drawing with the special color . Here goes a example of drawing a dashed-line circle.enjoy!
Round cornered anti-aliased dynamically sized button. $w=40; $h=20; $im = ImageCreate($w,$h); $white=ImageColorAllocate($im,255,255,255); ImageFilledRectangle($im,0,0,$w,$h,$white); imagecolortransparent ($im, $white); ImageTTFText ($im, $h+ceil($h/3)+1, 0, -1, $h-1, $col1, "arialbd.ttf", "O"); ImageTTFText ($im, $h+ceil($h/3)+1, 0, $w-$h, $h-1, $col1, "arialbd.ttf", "O"); ImageTTFText ($im, $h+ceil($h/3)+1, 0, 1, $h-1, $col1, "arialbd.ttf", "O"); ImageTTFText ($im, $h+ceil($h/3)+1, 0, $w-$h-2, $h-1, $col1, "arialbd.ttf", "O"); $points=array( 1,round($h/2), round($h/4),$h-round($h/4), round($h/2),$h, $w-(round($h/2)),$h, $w-(round($h/4)),$h-round($h/4), $w-2,round($h/2), $w-round($h/4),round($h/4), $w-round($h/2),0, round($h/2),0, round($h/4),round($h/4) ); imagefilledpolygon ($im, $points, 10, $col1); header("content-type: image/gif"); header("Content-Disposition: filename=name.gif"); ImageGif($im); ImageDestroy($im);
imagearc example works not well,as it lacks of this line "$white = imagecolorallocate($img, 255, 255, 255); imagefill($img,0,0,$white); $black = imagecolorallocate($img, 0, 0, 0); "
I didn't have much luck with the other two functions, one of them makes circles that look like they've been printed on a dot-matrix printer. This simple function builds a border out of circles, seems to work nicely.
[note-Apache/1.3.29 (Win32) PHP/4.3.4] The imagearc (and imageellipse) functions do not accept line thicknesses when drawn from 0 to 360 degrees. Drawing from 0 to 359 and again from 359 to 360 does create an ellipse with the current line thickness. Jerry
To fill an arc (DiameterX != DiameterY): To close the arc with 2 lines (DiameterX != DiameterY): An example:
Here's a dashed circle function:
Here's the function to draw rotated ellipses again. This time I've optimised it a bit, fixed the no-fill bug, and used a 'squishratio' rather than a 'radiusmodifier', to make the curves perfect, so ignore my previous version.
The wierd thing is that the first two integers tell where to place the "circle". So for example I first create the "pallet" to place the circle on. $image = imagecreate(500, 500); (this makes a huge 500x500 gif :) ) $colorBody = imagecolorallocate($image, 0, 0, 0); (make the default color of the "pallet" black $circleColor = imagecolorallocate($image, 255, 0, 255); (going to make the circle an ugly pink color) imagearc($image, 250, 250, 300, 300, 0, 360, $circleColor); Places the image in the center (250,250) and the circle is 300 pixels in diameter. Hope this helps. Travis Kent Beste
I wrote a simple function that can draws an arc counter-clockwisekly. Here it is : The params of this function is exactly the same as the usual imagearc function.
Heres a function to make a curve between two points... This will be a downward curve but it wouldn't be hard to make a similar function to make an upward curve. The first point has to be to the left of the second point ($x1To do filled arcs, try something like this: ...well you get the point. It's a kludge, and *very* slow, but it's free.There is another way to fill an arc :I found a better way for drawing a pie chart: header ("Content-type: image/png"); $diameter = 100; $radius = $diameter / 2; $centerX = $radius; $centerY = $radius; $im = @ImageCreate ($diameter, $diameter) or die ("Cannot Initialize new GD image stream"); $background = ImageColorAllocate ($im, 0, 0, 0); $red = ImageColorAllocate ($im, 176, 0, 0); function fill_arc($start, $end, $color) { global $diameter, $centerX, $centerY, $im, $radius; imagearc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color); imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $radius, $centerY + sin(deg2rad($start)) * $radius, $color); imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end)) * $radius, $centerY + sin(deg2rad($end)) * $radius, $color); imagefill ($im,$centerX + $radius * 0.5 *cos(deg2rad($start+($end-$start)/2)), $centerY + $radius * 0.5 * sin(deg2rad($start+($end-$start)/2)), $color); } fill_arc(0,30,$red); // Will make a red filled arc, starting at 0 degrees, ending at 30 degrees ImagePng ($im);
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)