首頁  >  文章  >  後端開發  >  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