imageantialias() - gd函数(图像处理)
imageantialias()
(PHP 4 >= 4.3.2, PHP 5, PHP 7)
是否使用抗锯齿(antialias)功能
说明
imageantialias(resource $image,bool $enabled): bool对线段和多边形启用快速画图抗锯齿方法。不支持 alpha 部分。使用直接混色操作。仅用于真彩色图像。
不支持线宽和风格。
使用抗锯齿和透明背景色可能出现未预期的结果。混色方法把背景色当成任何其它颜色使用。缺乏 alpha 部分的支持导致不允许基于 alpha 抗锯齿方法。
参数
$image由图象创建函数(例如imagecreatetruecolor())返回的图象资源。
$enabled是否启用抗锯齿。
返回值
成功时返回TRUE
,或者在失败时返回FALSE
。
范例
A comparison of two lines, one with anti-aliasing switched on
以上例程的输出类似于:
注释
Note:此函数仅在与 GD 库捆绑编译的 PHP 版本中可用。
参见
imagecreatetruecolor()
新建一个真彩色图像
If you can't be bothered creating (or searching for) a full screen antialias function. You can actually cheat (well a bit of a dirty inefficient hack really!!) and perform a fake antialias on an image by using 'imagecopyresampled'... first create your source image twice the size of what you really want. Then use 'imagecopyresampled' to shrink it to half the size, the function automatically interpolates pixels to create an antialias effect! I've used this in a pie chart function and it works brilliantly, not as slow as I thought it might be! the rough code below should give you the idea...
So far using PHP 5.0.4 I've managed to get Imageantialias() to work well with: ImageLine() ImagePolygon() but not with: ImageArc() ImageEllipse() ImageFilled*() You can still draw antialiased filled polygons by drawing a hollow polygon on top of a filled one with the same dimensions:
The following function draws an AntiAliased (unfilled) Ellipse. It is used just liked the nomral ImageEllipse function. The optional parameter sets the number of segments... function ImageEllipseAA( &$img, $x, $y, $w, $h,$color,$segments=70) { $w=$w/2; $h=$h/2; $jump=2*M_PI/$segments; $oldx=$x+sin(-$jump)*$w; $oldy=$y+cos(-$jump)*$h; for($i=0;$i
Having tried long and hard to get a decent antialiased circle function, I finally gave in a wrote something from scratch. Its very very naive - basically examining every single pixel in the enclosing square, but as a result produces very nice antialiasing, with decent control over stroke width, antialiasing amount and tightness of antialiasing. I'm sure it could be optimised considerably, but it was fast enough for what I was doing. Hope its of some use.
I did a search in google and got following url: http://www.isocalc.com/tutorials/antialias.htm With this tutorial I was able to write a function to convert this algorithm into php, the result for a filled circel is this: An improvement would be to draw the inner rectangle or more rectangles in the circle with the builtin rectangle function to reduce the usage of imagesetpixel() from (2*r)^2 to 2*Pi*(r + epsilon), in other words, the dependency on r would break down from square to linear. Another improvement would be to determine filled and unfilled triangles in the observed pixel and calculate their areas, so we can get rid of the inner loops for getting the fraction filled/unfilled. One can easily modify this function to solve other problems like lines, unfilled circles, etc.
The only trick I found to draw an antialiased polygon AND keep it transparent (to use them as overlays in google maps for example)... make two images and merge them. Order of operations is important and the transparency color of the final image must be set after the merge:
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)