PHP's question of drawing a rectangle

Source: Internet
Author: User
& Amp; lt ;? Phpheader (& #039; Content-type: imagejpeg & #039;); $ width120; $ height40; $ imgimagecreatetruecolor ($ width, $ height); $ colorBgimagecolorallocate ($ img, rand (200,255), rand (200,255), rand (200,255); $ col... 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 );

Draw a rectangle with php. In the imagerectangle ($ img, 0, 0, $ width-1, $ height-1, $ colorBorder) function, why is the coordinate in the lower right corner not $ width, $ height, but $ width-1, $ height-1. I don't understand it here. Thank you very much for your advice!

Reply content:

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 );

Draw a rectangle with php. In the imagerectangle ($ img, 0, 0, $ width-1, $ height-1, $ colorBorder) function, why is the coordinate in the lower right corner not $ width, $ height, but $ width-1, $ height-1. I don't understand it here. Thank you very much for your advice!

After the width is reduced, the color will not fill the entire canvas, and a pixel width will be left as the border. In fact, the two colors are superimposed to generate a pixel difference set. It looks like there is a pixel border.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.