Home  >  Article  >  Backend Development  >  PHP画图的一些疑义

PHP画图的一些疑义

WBOY
WBOYOriginal
2016-06-13 13:19:50792browse

PHP画图的一些疑问


PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$src621 = imagecreate(200,200); 
$yellow = imagecolorallocate($src621, 255, 255, 0);
$red = imagecolorallocate($src621, 255, 0, 0);
$green = imagecolorallocate($src621, 0, 255, 0);
imagerectangle($src621, 100, 50, 150, 150, $green);
imagefill($src621, 0, 0, $red);
header("Content-Type: image/png");
imagepng ($src621);
imagedestroy($src621);



结果:


疑问一、yellow颜色是怎么被画上去的?
疑问二、imagefill函数的中间2个参数有什么用?(自己测试发现,改变不起作用,如果改变大了,就没有填充颜色)

求牛人解答。谢谢!!

------解决方案--------------------
注: 第一次对 imagecolorallocate() 的调用会填充背景色。 
//imagefill($src621, 0, 0, $red);//注释掉这句你就看出来了
imagefile是点区域填充,左上角是(0,0)
为黄色,意思把所有红色(选区)填充为$red,像ps里的油漆筒
这个选区是关键,为啥里面的红色未被填充,那是因为
imagerectangle($src621, 100, 50, 150, 150, $green);//矩形的边框为绿色
这个green色隔开了红色,也就是里面给与外面红不在一个选区
不信你再改一下这句测试
imagefill($src621, 101, 51, $red);//这样点跑矩形里面了,选中的是矩形里面的红区域


------解决方案--------------------
对于 imagecreate 创建的资源,第一个创建的颜色为背景色
imagefill函数的中间2个参数是充填的起点坐标(原点),从这点出发直至边界,所有可到达的位置并且颜色与原点相同的都设为指定色

用于你在 imagefill 之前换了一个空心矩形(imagerectangle)所以该矩形的边缘是作为边界的
不被充填,自然也就露出背景了
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn