Home > Backend Development > PHP Tutorial > PHP画一个矩形的问题

PHP画一个矩形的问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:17:15
Original
1343 people have browsed it

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

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

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template