php gd library

gd common function

as imagecreatetruecolor () returns an image identifier, representing a size x_sizeand a y_sizeblack image.  

After a successful return to image resources, failed to return after FALSE

 

int imagecolorallocate ( resource $image , int $red , int $green , int $blue )
 
The first time imagecolorallocate () call will based image fills the background color palette, which uses imagecreate () image is created.
 
bool imagefill ( resource $image , int $x , int $y , int $color )
ImageFill () in the imagecoordinates of the image x, y(top left is 0, 0) with the colorcolor area fills performed (i.e., x, y point of the same color and adjacent dots will be filled)
 
imagefilledrectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color

In imagethe image drawing with a colorfilled rectangle of color, which is the upper-left coordinates x1, y1bottom-right corner coordinates x2, y2. 0, 0 is the most upper-left corner of the image. 

 

imageellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color )

Draw an ellipse on the specified coordinates. 

 

imagefilledellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color )

Videos and filled into a specified ellipse image.

 

bool imagepng ( resource $image [, string $filename ] )

imagepng () GD image stream ( image) output PNG format to the standard output (usually the browser),

If a filenamegiven file name will be output to the file.

<?php
$im = imagecreatefrompng("test.png");
imagepng($im);
?>
 
imagedestroy () releases the imagememory associated with it.
 
Array getimagesize ( String $filename[, Array &$imageinfo]) to obtain image size
 
imagefilledarc ( resource $image , int $cx , int $cy , int $width , int $height , int $start , int $end , int $color , int $style )
 
bool imagestring ( resource $image , int $font , int $x , int $y , string $s , int $col )

the imagestring () with colthe color string sdrawn to the imageimage represented x, yat coordinates (This is the string left corner, the upper left corner of the entire image is 0,0). If you fontare 3, 4 or 5, use the built-in font. 

imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )

imageline () with a colorcolor image imagefrom the coordinates x1, y1the x2, y2(top left is 0, 0) to draw a line segment.  

Specified imagedraw an elliptic arc and a filler.

 

<?php
header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
      or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>
 
 
 
Practical application:
Draw a pie chart:
 
<? PHP
 header ( "Content-of the type: Image / PNG" );
 // create a canvas 
$ img = as imagecreatetruecolor (800, 600 );
 // add color 
$ Blue = imagecolorallocate ( $ img , 0, 0, 255); 
ImageFill ( $ IMG , 0, 0, $ Blue ); // fill color // / ImageFill (IMG $, 0, 0, $ Blue); $ Red = imagecolorallocate ( $ IMG , 255, 0, 0 ); // add filled fill effects $ Green = imagecolorallocate ( $ IMG , 0, 255, 0 ); // draw an arc // imagearc ($ IMG, 400, 300, 300, 300, 270, 0, $ Green); // draw a circular arc and fill color / * 1IMG_ARC_PIE 2.IMG_ARC_CHORD 3.IMG_ARC_NOFILL 4.IMG_ARC_EDGED IMG_ARC_PIE are mutually exclusive and IMG_ARC_CHORD ; IMG_ARC_CHORD except that a line connecting the start and end points, IMG_ARC_PIE circular boundary is generated. IMG_ARC_NOFILL specified arc or chord profile only, not filling. IMG_ARC_EDGED with straight lines indicate start and end points to the center point, and the I MG_ARC_NOFILL used with the method of drawing a pie chart is a good profile (without filling). * / // ImageFill filling if it is circular or circular inner populates filled circular external addition to location according // 600 300 $ Gray = imagecolorallocate ( $ IMG , 0xC0, 0xC0, 0xC0 ); $ DarkGray = imagecolorallocate ( IMG $ , 0x90, 0x90, 0x90 ); $ Navy = imagecolorallocate ($ IMG , 0x00, 0x00, 0x80 ); $ darknavy = imagecolorallocate ( $ IMG , 0x00, 0x00, 0x50 ); $ Red = imagecolorallocate ( $ IMG , 0xFF, 0x00, 0x00 ); $ darkred = imagecolorallocate ( $ IMG , 0x90, 0x00, 0x00 ); for ( $ I = 300; $ I > 250; $ I - ) {
// draw resources oval, x-axis semimajor axis y color semiminor the ImageFilledArc (
$ IMG , 400, $ I , 400, 350, 0, 45, $ DarkGray , 0 ); the ImageFilledArc ( $ IMG , 400, $ I , 400, 350, 45, 270,darkred $ , 0 ); the ImageFilledArc ( $ IMG , 400, $ I , 400, 350, -90, 0, $ darknavy , 0 ); }
// here drawn first with a relatively dark color such shadow effect can have the ImageFilledArc (
$ IMG , 400, 250, 400, 350, 0, 45, $ Gray , 0 ); the ImageFilledArc ( $ IMG , 400, 250, 400, 350, 45, 270, $ Red , 0 ); the ImageFilledArc ( $ IMG , 400, 250, 400, 350, -90, 0, $ Navy , 0 );
// bright colors draw imagepng (
$ img );
// png format to output images to the browser imagedestroy (
img $ );
// destroy image resources

effect:

 

Security Code:

? < PHP
 $ IMG = as imagecreatetruecolor (200 is, 50 );
 $ STR = "ABCDEFG" ;
 $ F = imagecolorallocate ( $ IMG , 0, 0, 0 ); 
ImageFill ( $ IMG , 0, 0, $ F );
 $ S = str_shuffle ( $ STR ); // disrupt into unordered array
 for ( $ I = 0; $ I <. 4; $ I ++ ) {
         $ C = substr ( $ STR , RAND (0, strlen ( $ S ) ), 1 );
         $ Color = imagecolorallocate($img, 50, 50, 50);
        imagestring($img, 6, 10+$i*40, rand(10,30), $c, $color);
        imageline($img, rand(0,30), rand(0,50), rand(150,200), rand(0,50), $color);
}
$color = imagecolorallocate($img, 0, 0, 255);

header("Content-type:image/png;charset=utf8");
imagepng($img);
imagedestroy($img);

Renderings:

 

 

 

Guess you like

Origin www.cnblogs.com/webcyh/p/11300657.html