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.