Rumah  >  Artikel  >  pembangunan bahagian belakang  >  PHP画一个矩形的问题

PHP画一个矩形的问题

WBOY
WBOYasal
2016-06-06 20:17:151254semak imbas

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,此处不明白,请各位老师指教,非常感谢!

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

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn