PHP notes GD library image creation/simple verification code

Source: Internet
Author: User


Yan 18 Public Service PHP training class address: YY Channel 88354001 Learning Community: www.zixue.it

PHP Drawing: such as verification code, thumbnails, plus watermark to use the GD library, so to open the GD2 library, in order to use

First find php.ini in Extension=php_gd2.dll remove the front semicolon, and then restart Apache, create a picture can be used

     /* General steps for drawing:     1. Create a canvas     2. Create a pigment     3. Paint or Write     4. Save     5. Destroy resources *//Create canvas $img =imagecreatetruecolor ( 300,200); Create pigments $bg =imagecolorallocate ($img, 30,255,255); Canvas Fill Color Imagefill ($img, 0,0, $BG); Save Picture if (Imagepng ($img, './01.png ')) {     

Simple Verification Code

Create Picture $im = Imagecreatetruecolor (+);  Set the background to blue $blue = Imagecolorallocate ($im, 100, 255, 255); Create pigments $imgcolor =imagecolorallocate ($im, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255)); Fill background color Imagefill ($im, 0, 0, $blue);   Draw the interference line for ($i =0; $i <4; $i + +) {               imageline ($im, Rand (0,20), 0,100,rand (0,60), $imgcolor);}  Draw noise for ($i =0; $i <100; $i + +) {          imagesetpixel ($im, Rand (0,50), Rand (0,30), $imgcolor);}  Write String $str =substr (str_shuffle (' ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789 '), 0,4);   Imagestring ($im, 4,10,10, $str, $imgcolor);  

Verification code Note Save format, UTF8 no BOM format, only save as UTF8 will appear garbled

The output random verification code is:

PHP notes GD library image creation/simple verification 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.