imagefilledrectangle() - gd函数(图像处理)
imagefilledrectangle()
(PHP 4, PHP 5, PHP 7)
画一矩形并填充
说明
imagefilledrectangle(resource $image,int $x1,int $y1,int $x2,int $y2,int $color): boolimagefilledrectangle()在$image图像中画一个用$color颜色填充了的矩形,其左上角坐标为$x1,$y1,右下角坐标为$x2,$y2。0, 0 是图像的最左上角。
If you want to draw a rectangle with rounded corners, you can use this simple function... Rectangle starts at x1y1 and ends at x2y2. $radius defines radius of circled corner.
I've made a function to make full color gradients: More functions at http://www.sphoera.com
I wanted to clear an image, and set it to full transparent. imagefilledrectangle() seems to ignore alpha channel and alpha blending. Use imagefill() instead:
a simple way of using imagerectangle to create a percentage bar
I would like to inform developers about a problem I encountered when trying to use imagefilledrectangle. I noted that the order in which the start and end y coordinates are listed is extremely important. as in the statements below. if($this->d_values[$i]['unit_value'] img,$position_x, $start_y , $end_x, $end_y ,$d_color); else imagefilledrectangle($this->img, $position_x,$ end_y , $end_x, $start_y,$d_colour); Thanks
Important quirk to note: While imagerectangle will allow you to use a different order of your coordinates (such as bottom-left to upper-right), imagefilledrectangle will only work correctly if you use top-left to bottom-right as indicated in the docs.
The issue with filling using a rectangle is caused in your code by having alpha blending turned on before rendering the filled rectangle. Alpha blending causes what you draw on the image to be blended with whatever is already on the image according to the alpha channels of each. Therefore, because blending is on, and because the rectangle's fill colour is completely transparent, the blending of the existing image content with the transparent rectangle results in no change to the existing image. With blending off, when drawing to the image what you draw completely replaces what is already there. So, drawing the rectangle in this case results in the original content of the image being completely replaced with a transparent rectangle. So in order to use imagefilledrectangle() to erase an image to transparency, you need to turn off alpha blending first. I guess the reason imagefill() works with alpha blending on is because it does not perform any alpha blending - it always works without alpha blending regardless of the setting. I suspect there are reasons for this to do with alpha channels complicating edge detection. I would recommend using imagefilledrectangle() to create a blank transparent image resource instead of imagefill() because it is undoubtedly much faster in probably all cases. Here is some example code to blank an image to transparent, assuming $im is a successfully created image:
The examples in function imagettfbbox() gave me many problems because of misunderstand of how the text is positionned in the box. So I did a new example: - writing a text - in the correct position in its box - with a padding around Enjoy ! Mike
It looks like there are waves beetween the points, but it's straight.
Thanks terereese. it took me over two hours to figure that one out. it worked locally: imagefilledrectangle(imagresource, int x1, int x2, int y1, inty2, color) BUT remote on my provider only this worked: imagefilledrectangle(imagresource, int x1, int y2, int x1, inty1, color) Any ideas why and where?
As of PHP 5, it seems to be no longer necessary to draw the rectangle from the upper left to the lower right corner. This led me into big trouble porting a script developed under PHP 5 to PHP 4.
That script draws Serpinski's carpet:
As stated above, it needs to go from the top left corner to the bottom right corner. Just use this to flip it if neccessary: // flip them if neccessary (x3, y3 are temp vars) if($x1 > $x2) { $x3 = $x2; $x2 = $x1; $x1 = $x3; } if($y1 > $y2) { $y3 = $y2; $y2 = $y1; $y1 = $y3; } ImageFilledRectangle($im, $x1, $y1, $x2, $y2, $color);
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)