Last time, GD was used as a variety of geometries, as well as filling colors. Among them, this more complicated situation is intentionally
Remove to the back, this is the filler color of any polygon and any polygon.
Header ("Content-Type: Image / PNG");
$ IM = ImageCreate (200, 100);
$ colorAllocate ($ IM, 0, 0, 0);
$ colorAllocate ($ IM, 0, 255, 0);
$ PARRAY = Array (40, 10, 60, 10, 70, 20, 60, 50, 40, 50, 20);
/ / Define an array, 12 members are 6 points of horizontal length.
ImagePolygon ($ IM, $ PARRAY, 6, $ COL_GRN);
// This is a function that draws any polygon, $ PARRAY is an array just defined,
// 6 shows six points. Note that the six points are connected to the hexagon.
// Do not have to be in order to close the graphic, the same point is added to the first point.
ImagePNG ($ IM);
ImageDestroy ($ IM);
?>
You should have already thought that the function of any polygon fill color:
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);
$ PARRAY = Array (40, 10, 60, 10, 70, 20, 60, 50, 40, 50, 20);
ImageFilledPolygon ($ IM, $ PARRAY, 6, $ COL_GRN);
ImagePNG ($ IM);
ImageDestroy ($ IM);
?>
Ok. Below we can write on the image. However, don't be happy, I want to write Chinese characters to pay some trouble.
This will gradually explain it later. Let's take a look at how to write Western characters.
Header ("Content-Type: Image / PNG");
$ IM = ImageCreate (200, 250);
$ colorAllocate ($ IM, 0, 0, 0);
$ coloraories ($ IM, 255, 192, 0);
$ Str = "This is A Test."
Imagestring ($ IM, 1, 10, 10, $ STR, $ COL_ORN);
Imagestring ($ IM, 2, 10, 30, $ STR, $ COL_ORN);
ImageString ($ IM, 3, 10, 60, $ STR, $ COL_ORN);
ImageString ($ IM, 4, 10, 100, $ STR, $ COL_ORN);
Imagestring ($ IM, 5, 10, 150, $ STR, $ COL_ORN);
// This is called imageString five consecutive positions, in different positions,
// The string $ Str is output from a small to large font.
// ImageString function only supports five types (1 ~ 5)
ImagePNG ($ IM);
ImageDestroy ($ IM);?>
Look at:
//Header ("Content-Type: Image / PNG");
$ IM = ImageCreate (200, 250);
$ colorAllocate ($ IM, 0, 0, 0);
$ coloraories ($ IM, 255, 192, 0);
$ Str = "This is A Test."
ImageStringup ($ IM, 1, 10, 180, $ STR, $ COL_ORN);
Imagestringup ($ IM, 2, 20, 180, $ STR, $ COL_ORN);
ImageStringup ($ IM, 3, 40, 180, $ STR, $ COL_ORN);
ImageStringup ($ IM, 4, 70, 180, $ STR, $ COL_ORN);
ImageStringup ($ IM, 5, 110, 180, $ STR, $ COL_ORN);
// The function name is replaced by imageStringup, the usage is constant.
// is the text of the output.
ImagePNG ($ IM);
ImageDestroy ($ IM);
?>
At the same time, if you can use the function of the output character, if you can know the width, height of the words of different font types in the image.
What will be how convenient for the location of the arranging output character! PHP is provided to us: imagefontwidth () and
ImageFontHeight (), its parameters are simple, only one: ie the word type. For example imagefontwidth (5)
It is the width of each character of 5 characters, and imagefontheight (3) is the height of each character of 3 characters. so
Simple, it is not exemplified, and it is also useful in the following code.
Similar to the output string, imagechar and imagecharup output a single character, the use is less, and even
Needless - Whether characters or strings, you can use imageString and ImageStringup!
Below, I use some of the code I have done to draw the stock K-line analysis map, put the content system mentioned earlier
Apply it. Because of the database, you can't take the original code to take it back to test. Can only construct some
Data, simulate the stock market market from the database. In view of the people who understand stock K lines, there may not be much, you may not know that K
How to draw a method. However, I can't talk about it here, how is the K line? It is only to introduce such a series of methods. Wait for painting
Ok, you will definitely see that this is really seen before.
PHP
Header ("Content-Type: Image / PNG");
$ IM = ImageCreate (640, 260);
$ bkground = imagecolorallocate ($ IM, 255, 255, 255);
$ DATA = ImageColoralLocate ($ IM, 0, 0, 0);
$ GID = ImageColoralLocate ($ IM, 200, 200, 160);
$ UPLINE = ImageColoralLocate ($ IM, 255, 0, 0);
$ DNLINE = ImageColoralLocate ($ IM, 0, 175, 175);
$ D5LINE = ImageColoralLocate ($ IM, 255, 127, 0);
$ D20LINE = ImageColoralLocate ($ IM, 0, 0, 127);
$ d10line = imagecolorallocate ($ IM, 255, 0, 255);
// Define the color used to paint various objects.
For ($ I = 20; $ i <= 220; $ i = 25)
Imageline ($ IM, 60, $ I, 560, $ I, $ GIRD);
For ($ j = 60; $ j <= 560; $ j = 25)
Imageline ($ IM, $ J, 20, $ J, 220, $ GID);
// Calculate the position in advance, lattice width, draw line with for loop, and save more.
$ zzg = 10.55;
$ zzd = 7.63;
$ LZG = 10350;
/ / Assuming stock market data,
// $ zzg is the highest value of this time you need to analyze, assuming is 10.55 yuan.
// $ zzd is the lowest price of this period of analysis, assuming is 7.63 yuan.
// $ LZG is the highest volume of this time you need to analyze, assuming is 10,350 hands.
// This is an important data for calculating the "scale" of the coordinate grid.
$ BL = $ zzg- $ zzd;
// The highest price difference between the lowest price. According to the proportion of the total height of the grid,
// You can give a practical price in the grid.
For ($ I = 1; $ i <= 7; $ i )
{
$ y = $ i * 25-10;
/ / The appropriate height (ordinate) of the label mark is calculated according to the position of the grid line.
$ Str = Number_Format ($ ZZG - ($ I-1) / 6 * $ BL, 2, ".", ",");
// Calculate the price corresponding to each discretion and format the string.
$ x = 55-imagefontwidth (2) * Strlen ($ STR);
// According to this string, the width to take up will calculate the appropriate abscissa.
Imagestring ($ IM, 2, $ X, $ Y, $ STR, $ DATA);
// Write this string.
}
$ Str = Number_Format ($ LZG, 0, ".", ",");
Imagestring ($ IM, 2, 564, 164, $ STR, $ DATA);
$ Str = Number_Format ($ LZG / 2, 0, ".", ",");
Imagestring ($ IM, 2, 564, 189, $ STR, $ DATA);
// Due to only two of the scale of the transaction volume, it is not critable with cyclic writing.
// If the quantity is more, you should also use a loop.
// Since a K-line map is to draw countless small K columns, a small K-ray column is written into a function.
Function Kline ($ IMG, $ KP, $ ZG, $ ZD, $ SP, $ CJL, $ II)
// Parameters: $ IMG image; $ KP $ ZG $ zd $ SP is open, maximum, lowest, closed
// $ CJL transaction; $ II counter, represents the serial number of the K column.
{
Global $ BL, $ ZZD, $ LZG;
// Declarelying $ BL, $ ZZD, $ LZG in the function is global variable.
$ H = 150; // K line column region height is 150.
$ HH = 200; // k wire column area, the total height of the volume column region is 200.
IF ($ SP <$ KP)
$ lineColor = ImageColorAllocate ($ IMG, 0, 175, 175);
// If the closing price is lower than the opening, it is the Yin Line, with a cyan
Else
$ LINECOLOR = ImageColoralLocate ($ IMG, 255, 0, 0);
/ / Otherwise it is a yang line, with red.
$ x = 58 $ II * 4;
/ / Calculate the horizontal coordinates according to the K-column sequence number.
$ y1 = 20 $ h - ($ KP- $ zZD) / $ BL * $ H;
/ / The corresponding longitudinal coordinates are calculated according to the opening price.
$ y2 = 20 $ h - ($ SP- $ zZD) / $ BL * $ H;
/ / The corresponding longitudinal coordinate is calculated based on the closing price.
$ Y3 = 20 $ H - ($ ZG- $ ZZD) / $ BL * $ H;
/ / The corresponding longitudinal coordinates according to the highest price.
$ Y4 = 20 $ H - ($ ZD- $ zZD) / $ BL * $ H;
/ / The corresponding longitudinal coordinates are calculated according to the lowest price.
$ Y5 = 20 $ HH- $ CJL / $ LZG * ($ HH- $ H);
/ / The corresponding longitudinal coordinates are calculated based on the amount of transaction.
IF ($ Y1 <= $ Y2) ImageFilledRectangle ($ IMG, $ X-1, $ Y1, $ X 1, $ Y2, $ LINECOLOR);
Else ImageFilledRectangle ($ IMG, $ X-1, $ Y2, $ X 1, $ Y1, $ LINECOLOR);
// Spend 1 to 1, span is 3. That is, a small padding rectangle with a width of 3.
// The height and ordinate are determined by the opening and closing price.
// Test found that this function must be before the upper left coordinates written before the lower right point coordinates.
/ / Rather than automatic judgment is left on the left, and it is right.
ImageFilledRectangle ($ IMG, $ X-1, $ Y5, $ X 1, 220, $ LINECOLOR);
/ / Pain the intersection of the intersection according to the volume of the transaction.
Imageline ($ IMG, $ X, $ Y3, $ x, $ y4, $ linecolor);
/ / According to the highest price, the lowest price is drawn.
}
// test one. Opened 8.50 up to 8.88 minimum 8.32 closed 8.80 transactions 6578.
Kline ($ IM, 8.50, 8.88, 8.32, 8.80, 6578, 1);
// Draw a again. Opened 8.80 up to 8.50 minimum 8.50 Terminal 8070.
/ / The light of the light head is!
Kline ($ IM, 8.80, 9.50, 8.80, 9.50, 8070, 2);
// Come back. The opening 9.80 maximum 9.80 minimum 8.90 closed 9.06 transaction 10070 hand.
// Lost! How good is it yesterday.
Kline ($ IM, 9.80, 9.80, 8.90, 9.06, 10070, 3);
// ......
ImagePNG ($ IM);
ImageDestroy ($ IM);
?>
Of course, you have to write this every day, too much trouble. I am doing data from the database.
This time I said here.