& 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.