首页  >  文章  >  后端开发  >  PHP画一个矩形的问题

PHP画一个矩形的问题

WBOY
WBOY原创
2016-06-06 20:17:151251浏览

header('Content-type:image/jpeg');
$width = 120;
$height = 40;
$img = imagecreatetruecolor($width, $height);
$colorBg = imagecolorallocate($img, rand(200,255), rand(200,255),rand(200,255));
$colorBorder = imagecolorallocate($img, 255, 0, 0);
imagefill($img, 0, 0, $colorBg);
imagerectangle($img, 0, 0, $width-1, $height-1, $colorBorder);
imagejpeg($img);

用php绘制一个矩形,在函数imagerectangle($img, 0, 0, $width-1, $height-1, $colorBorder)中, 为什么右下角的坐标不是$width,$height,而是$width-1,$height-1,此处不明白,请各位老师指教,非常感谢!

回复内容:

header('Content-type:image/jpeg');
$width = 120;
$height = 40;
$img = imagecreatetruecolor($width, $height);
$colorBg = imagecolorallocate($img, rand(200,255), rand(200,255),rand(200,255));
$colorBorder = imagecolorallocate($img, 255, 0, 0);
imagefill($img, 0, 0, $colorBg);
imagerectangle($img, 0, 0, $width-1, $height-1, $colorBorder);
imagejpeg($img);

用php绘制一个矩形,在函数imagerectangle($img, 0, 0, $width-1, $height-1, $colorBorder)中, 为什么右下角的坐标不是$width,$height,而是$width-1,$height-1,此处不明白,请各位老师指教,非常感谢!

宽度减一以后颜色就不会填充整个画布了,会留有一个像素宽度做边框,实际上就是两种颜色叠加产生一个像素的差集看起来有一个像素的边框而已

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn