Some questions about drawing in PHP

Source: Internet
Author: User
PHP drawing questions: PHPcode $ src621 = imagecreate (200,200); $ yellow = imagecolorallocate ($ src621, 255,255, 0); $ red = imagecoloral PHP drawing questions


PHP code
  $src621 = imagecreate(200,200); $yellow = imagecolorallocate($src621, 255, 255, 0);$red = imagecolorallocate($src621, 255, 0, 0);$green = imagecolorallocate($src621, 0, 255, 0);imagerectangle($src621, 100, 50, 150, 150, $green);imagefill($src621, 0, 0, $red);header("Content-Type: image/png");imagepng ($src621);imagedestroy($src621);


Result:


Question 1: How is the color of yellow painted?
Question 2: What is the use of the two parameters in the middle of the imagefill function? (Test by yourself. changes do not work. if the changes are large, there will be no fill color)

Please answer. Thank you !!

------ Solution --------------------
Note: The first call to imagecolorallocate () will fill in the background color.
// Imagefill ($ src621, 0, 0, $ red); // comment out this sentence and you will see it.
Imagefile is filled in the dot area, and the upper left corner is (0, 0)
It is yellow, meaning to fill all the red (selection area) with $ red, like the paint tube in ps
This constituency is the key. why is the red in it not filled? that's because
Imagerectangle ($ src621, 100, 50,150,150, $ green); // The border of the rectangle is green.
The green color is separated by red, that is, the inside is given with red outside of a selection area.
Do not believe it. try again.
Imagefill ($ src621, 101, 51, $ red); // in this way, the red area in the rectangle is selected.


------ Solution --------------------
For resources created by imagecreate, the first created color is the background color.
The two parameters in the middle of the imagefill function are the starting point coordinates (origin) of the filling. From this point to the boundary, all reachable locations and the same color as the origin are set to the specified color.

Before imagefill, you change an image rectangle (imagerectangle). Therefore, the edge of the rectangle serves as the border.
If it is not filled, the background is naturally displayed.

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.