PHP using the GD library to paint and generate the code picture

Source: Internet
Author: User
Tags header imagejpeg resource

First of all to determine whether the php.ini settings to open the GD extension function, the test is as follows

Print_r (Gd_info ());

If there is a printout of the contents below, then the GD function is open:
Array
(
    [GD Version] => bundled (2.0.34 compatible)
    [FreeType Support] => 1
    [FreeType linkage] =& Gt With FreeType
    [T1lib Support] => 1
    [gif Read Support] => 1
    [gif Create Support] => 1
    [JPG Support ] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 
    [XBM Support] => 1
    [jis-mapped Japanese Font Support] => 
)

GD Paint general steps as follows:

1. Create a canvas resource

2. Create a color brush

3. Drawing

4. Save picture or Output picture

5. Destroying the Memory canvas resource

The test code is as follows:

!--? php header (content-type:image/jpeg);   $width = 400;  

Wide, high $height = 400; $image = Imagecreate ($width, $height);  First step: Create a blank image $white = imagecolorallocate ($image, 0, 0, 0); 

The first call to Imagecolorallocate () fills the background color of the palette-based image, which is the image created with Imagecreate (). $green = imagecolorallocate ($image, 0, 255, 0);  Step Two: Assign color to the image imageline ($image, 0, M, $green);  Step three: Draw line Imagerectangle ($image, 100,40,300,100, $green); Draw rectangular Imagearc ($image, 0, 360, $green); Draw round imagestring ($image, MB, M, PHP is Niubi honghong!, $green);
Write String $str =abcdefghjklmnpqrstuvwxyz23456789;
$randstr = substr (Str_shuffle ($STR), 0,4); Imagestring ($image, $randstr, $green); Verification Code Imagettftext ($image, 0, N, $green, & #39;/msjhbd.  ttf& #39, Chinese vsenglish);   Chinese validation//imagejpeg ($image, & #39;/test.jpg& #39;);  Save the picture under the current path as Test.jpg imagejpeg ($image);   Fourth step: Without file name, direct output to the Web page Imagedestroy ($image); Step Fifth: Destroy, Recycle resources?--> 

The test picture is as follows:

Note: GD library powerful can draw a variety of reports (such as histogram, pie chart, etc.), thumbnails, plus watermark and stock trend chart


 
  




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.