Talk about PHP graphing (ii) _php tutorial

Source: Internet
Author: User
Tags dashed line in degrees

The last time I said a simple way to avoid GD, and then use GD to make the simplest of a "picture"-line.
This time I'm going to draw straight down and say. The part that was explained in detail in the last code is not mentioned this time.

Header ("Content-type:image/png");
$im = imagecreate (200, 100);
$col _black = imagecolorallocate ($im, 0,0,0);
$col _orn = imagecolorallocate ($im, 255,192,0);
Use orange today.
Exactly the same usage as the Imageline function,
Imagedashedline ($im, 0,100,199,100, $col _orn);
This draws a dashed line.

Let's do an experiment. To illustrate a problem.
$col _yel = imagecolorallocate ($im, 255,255,0);
Yellow.
Imageline ($im, 0,99,199,99, $col _yel);
A yellow line is drawn at the bottom edge of the image.
Imageline ($im, 200,0,200,100, $col _orn);
Try to draw a clear line along the right edge of the image, and the result is nothing.
This shows that the width 200, height 100 of the image, its coordinate range is (0,0) to (199,99).

Imagepng ($im);
Imagedestroy ($im);
Let's finish this section first.
?>


Then the effect is cool! I am also now learning to sell. PHP4.0.6 above increases this usage--can be used alternately
Color Draw Line! Examples are as follows:

Header ("Content-type:image/png");
$im = imagecreate (200, 100);
$col _black = imagecolorallocate ($im, 0,0,0);
$col _orn = imagecolorallocate ($im, 255,192,0);
$col _red = imagecolorallocate ($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, 199, img_color_styled);

Imagepng ($im);
Imagedestroy ($im);
?>

Look at the effect.

One of the three lines that I separated with a blank line illustrates that. Defines an array $style whose members are a series of colors;
And then executes a function, and then uses the img_color_styled "color" to draw out such a magical "straight line"--
An alternating red, black, and orange effect. Take a closer look and you'll find that the red, black, and orange sequences are what we define
$style sequence of array members: Red, red, black, orange, orange, orange, black, and then round and round ...
Did you see that? Note that this function is only supported after PHP4.0.6.

With the basics of the lines I've explained in detail, I want to make a single generation of the functions of other geometric shapes. You need to be prompted, no matter
What kind of geometry to draw is nothing more than a few elements that capture this figure. Before the color, the elements of the various graphs are as follows:

Point, two elements: horizontal axis, ordinate

Rectangle, four elements: the upper-left corner, the lower-right corner of the horizontal, ordinate

Arc, this understanding: arcs can include arcs, elliptical arcs; Draw an arc, he can be a circle in 360 degrees, draw an elliptical arc, and he's drawn at 360 degrees.
into an ellipse; so the element of this arc is six: center point transverse, ordinate, horizontal axis long, longitudinal axis long, arc beginning, end point.

Look at the example below.

!--? Header ("Content-type:image/png"),
$im = imagecreate (+),
$col _blk = imagecolorallocate ($i M, 0,0,0);
$col _orn = imagecolorallocate ($im, 255,192,0);
$col _red = imagecolorallocate ($im, 255,0,0);
$col _grn = imagecolorallocate ($im, 0,255,0);
$col _blu = imagecolorallocate ($im, 0,0,255);

Imagesetpixel ($im, 20,10, $col _orn);
//A little bit, I wonder if I can see it?
Imagerectangle ($im, 25,20,95,55, $col _blu); The
//blue rectangle.
Imagearc ($im, 20,85,50,40,225,360, $col _grn);
//Green Elliptical Arc, center at (20,85), axis 50, longitudinal axis 40,225 degrees to 360 degrees.
//This shows that the beginning and ending point of the arc here is measured in degrees, and
//is calculated as a horizontal right direction of 0 degrees, clockwise.
Imagearc ($im, 160,60,40,40,0,360, $col _orn);
//Orange full circle. As long as the axis length and longitudinal axis looks, is a positive circle.
//High School we learned: Circle is a special case of the ellipse!
//finally draw an arc. Can the center of the circle be outside the image?
Imagearc ($im, 160,140,240,240,0,360, $col _red);
//Yes!

Imagepng ($im);
Imagedestroy ($im);
?

The drawing of course inevitably involves painting a certain area into a certain color. GD has three ways of coloring, one is the rectangular area coloring,
One is the shading of the enclosing area at the specified point, and the other is the area shaded by the specified color. Look at the following example:
Header ("Content-type:image/png");
$im = imagecreate (200, 100);
$col _blk = imagecolorallocate ($im, 0,0,0);
$col _orn = imagecolorallocate ($im, 255,192,0);
$col _yel = imagecolorallocate ($im, 255,255,0);
$col _red = imagecolorallocate ($im, 255,0,0);
$col _grn = imagecolorallocate ($im, 0,255,0);
$col _blu = imagecolorallocate ($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. Draws the rectangle directly.
I deliberately surround a small area with four rectangles of different colors,
To illustrate the second type of coloring.

Imagepng ($im);
Imagedestroy ($im);

Look at the effect.

?>

Then:

Header ("Content-type:image/png");
$im = imagecreate (200, 100);
$col _blk = imagecolorallocate ($im, 0,0,0);
$col _orn = imagecolorallocate ($im, 255,192,0);
$col _yel = imagecolorallocate ($im, 255,255,0);
$col _red = imagecolorallocate ($im, 255,0,0);
$col _grn = imagecolorallocate ($im, 0,255,0);
$col _blu = imagecolorallocate ($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. Draws the rectangle directly.
I deliberately surround a small area with four rectangles of different colors,
>//To illustrate the second type of coloring.

Imagefill ($im, 70,70, $col _grn);
This is the second kind of coloring.

Imagerectangle ($im, 120,40,190,90, $col _grn);
Draw a rectangle to make the box. In fact, any border can be framed.
Imagefilltoborder ($im, 130,50, $col _grn, $col _orn);
Paint the green rectangle in orange.
As long as the specified point is within the range of this "box", it is independent of the location of the point within the area.
This function actually works like this:
Starts at the specified point, outward, looks for the boundary of the specified color, stops if found,
If you can't find it, apply the dots to the color you want.

Imagepng ($im);
Imagedestroy ($im);

Look at the effect.
Now we have made the picture is colorful, but in the browser, the picture,
Right-click Properties: Only 214 bytes!

?>

This time, let's talk about this.

http://www.bkjia.com/PHPjc/508315.html www.bkjia.com true http://www.bkjia.com/PHPjc/508315.html techarticle The last time I said a simple way to avoid GD, and then use GD to make the simplest of a "picture"-line. This time I'm going to draw straight down and say. Explained in detail in the last code ...

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