PHP drawing (2)

xiaoxiao2021-03-06  64

The last step of avoiding the mapping method of avoiding the GD, and then uses GD to make the easiest "picture" - straight line.

I will then draw straight down this time. The part explained in detail in the last code, this time no later.

Header ("Content-Type: Image / PNG");

$ IM = ImageCreate (200, 100);

$ colorAllocate ($ IM, 0, 0, 0);

$ coloraories ($ IM, 255, 192, 0);

// Today use orange.

/ / The same usage is exactly the same as the imageline function.

ImageDashedLine ($ IM, 0, 100, 199, 100, $ COL_ORN);

// This will draw a dashed line.

// Let's take a test. It is used to illustrate a problem.

$ colorallocate ($ IM, 255, 255, 0);

// yellow.

Imageline ($ IM, 0, 99, 199, 99, $ col_yel);

// Painted a yellow line on the bottom of the image.

ImageLine ($ IM, 200, 0, 200, 100, $ COL_ORN);

// Try to paint a clear line in the right along the image, the result is nothing.

// This shows that the image of the width is 200, the height 100 is (0, 0) to (199, 99).

ImagePNG ($ IM);

ImageDestroy ($ IM);

// This will end first.

?>

This effect is cool! I am also a current study. PHP4.0.6 has added this usage - you can use alternating

Color line! Examples are as follows:

Header ("Content-Type: Image / PNG");

$ IM = ImageCreate (200, 100);

$ colorAllocate ($ IM, 0, 0, 0);

$ coloraories ($ IM, 255, 192, 0);

$ colorAllocate ($ IM, 255, 0, 0);

$ style = array ($ col_red, $ col_red, $ col_black, $ col_orn, $ col_orn, $ col_orn, $ col_black);

ImagesetStyle ($ IM, $ STYLE);

ImageLine ($ IM, 0, 50, 199, 50, IMG_COLOR_STYLED);

ImagePNG ($ IM);

ImageDestroy ($ IM);

?>

Look at the effect.

Among them, I divide the three lines that open, explain it. Define a array $ style, which is a series of colors;

Then execute a function, and after the IMG_COLOR_STYLED "color" is such a magical "straight" -

Red, black, orange alternating effect. Take a closer look at you will find that red, black, orange, is our definition

$ style array member sequence: red, red, black, orange, orange, orange, black, then weighted ...

do you understand? Note that this function is supported after php4.0.6.

With the foundation of the drawing line I explained in detail, I want to take a function of the other geometric graphics. Need to prompt everyone, no matter

Which geometric pattern is drawn, nothing more than a few elements of this graphic. It is not a color, and the elements of various graphics are as follows:

Point, two elements: horizontal coordinate, ordinate

Rectangle, four elements: horizontal, longitudinal coordinates of the upper left corner, the lower right corner

Arc, this is understood: the arc can include an arc, an elliptical arc; draw a circular arc to draw him 360 degrees can be a circle, and the elliptical arc is painted with him 360 degrees. So this arc is six: center Point horizontal, ordinate, horizontal axis, long longitudinal axis, start, end point.

Look at the following example.

Header ("Content-Type: Image / PNG");

$ IM = ImageCreate (200, 100);

$ colorAllocate ($ IM, 0, 0, 0);

$ coloraories ($ IM, 255, 192, 0);

$ colorAllocate ($ IM, 255, 0, 0);

$ colorAllocate ($ IM, 0, 255, 0);

$ coloraLocate ($ IM, 0, 0, 255);

ImagesEtPixel ($ IM, 20, 10, $ COL_ORN);

// Little little one, I don't know if I can see it?

ImageRectangle ($ IM, 25, 20, 95, 55, $ COL_BLU);

// Blue rectangle.

Imagearc ($ IM, 20, 85, 50, 40, 225, 360, $ COL_GRN);

// Green elliptical arc, center at (20, 85), horizontal axis 50, vertical axis 40, 225 degrees to 360 degrees.

// This shows that the arc start, the end point is measured at an angle.

// is 0 degrees in the direction of the right to the right, clockwise.

Imagearc ($ IM, 160, 60, 40, 40, 0, 360, $ COL_ORN);

// Orange's whole circle. As long as the horizontal axis is equal to the longitudinal axis, it is a circle.

// We have learned in high school: the circle is the special case of ellipse!

// finally painted a circular arc. Can the center be outside the image?

Imagearc ($ IM, 160, 140, 240, 240, 0, 360, $ COL_RED);

// Yun!

ImagePNG ($ IM);

ImageDestroy ($ IM);

?>

Of course, the mapping can be ignored to apply a certain area into some color. GD has three coloring methods, one is a rectangular area coloring,

One is the closed area coloration at the specified point, and the other is the region coloring surrounded by the specified color. Look at the following example:

Header ("Content-Type: Image / PNG");

$ IM = ImageCreate (200, 100);

$ colorAllocate ($ IM, 0, 0, 0);

$ coloraories ($ IM, 255, 192, 0);

$ colorallocate ($ IM, 255, 255, 0);

$ colorAllocate ($ IM, 255, 0, 0);

$ colorAllocate ($ IM, 0, 255, 0);

$ coloraLocate ($ IM, 0, 0, 255);

ImageFilledRectangle ($ IM, 20, 10, 100, 50, $ COL_BLU);

ImageFilledRectangle ($ IM, 5, 40, 50, 90, $ col_red);

ImageFilledRectangle ($ IM, 40, 80, 100, 95, $ COL_ORN);

ImageFilledRectangle ($ IM, 90, 35, 110, 90, $ col_yel);

// The above is the first coloring. Draw a rectangle directly.

// I deliberately use four different colors of rectangles from a small area,

// to illustrate the second coloring.

ImagePNG ($ IM);

ImageDestroy ($ IM);

// Look at the effect.

?>

then:

Header ("Content-Type: Image / PNG");

$ IM = ImageCreate (200, 100);

$ colorAllocate ($ IM, 0, 0, 0);

$ coloraories ($ IM, 255, 192, 0);

$ colorallocate ($ IM, 255, 255, 0);

$ colorAllocate ($ IM, 255, 0, 0);

$ colorAllocate ($ IM, 0, 255, 0);

$ coloraLocate ($ IM, 0, 0, 255);

ImageFilledRectangle ($ IM, 20, 10, 100, 50, $ COL_BLU);

ImageFilledRectangle ($ IM, 5, 40, 50, 90, $ col_red);

ImageFilledRectangle ($ IM, 40, 80, 100, 95, $ COL_ORN);

ImageFilledRectangle ($ IM, 90, 35, 110, 90, $ col_yel);

// The above is the first coloring. Draw a rectangle directly.

// I deliberately use four different colors of rectangles from a small area,

// to illustrate the second coloring.

ImageFill ($ IM, 70, 70, $ COL_GRN);

// This is the second coloring.

ImageRectangle ($ IM, 120, 40, 190, 90, $ COL_GRN);

// Pain a rectangle to make a box. In fact, you can make a frame.

ImageFillToBorder ($ IM, 130, 50, $ COL_GRN, $ col_orn);

// Paint the green rectangle into orange.

// As long as the specified point is within the range of this "box", it is independent of the location in the area in the area.

// This function is actually working this:

// From the specified point, look forward to the boundary of the specified color, if found, stop,

// If you can't find it, apply a point to the need to colors.

ImagePNG ($ IM);

ImageDestroy ($ IM);

// Look at the effect.

// Now we make a picture of a flower, but in the browser, on the picture,

// Right button -> Property: Only 214 bytes!

?>

This time, I said this.

转载请注明原文地址:https://www.9cbs.com/read-84908.html

New Post(0)