PHP uses the GD library to generate a verification code to draw Chinese characters on the image

Source: Internet
Author: User
Tags transparent color webp
: This article describes how to use the GD library to generate a verification code for PHP to draw Chinese characters on the image. For more information about PHP tutorials, see. PHP is not limited to creating HTML output. It can also create and process images in multiple formats, including GIF, PNG, JPEG, WBMP, and XPM. More conveniently, PHP can directly output the image data stream to the browser. To use the image processing function in PHP, you need to compile PHP together with the GD Library. The GD library and PHP may need other libraries, depending on the image format you want to process. You can use the image function in PHP to obtain the image size in the following formats: JPEG, GIF, PNG, SWF, TIFF, and MPEG-4. If used together with the exif extension, you can operate the information stored in the JPEG and TIFF image file headers so that you can obtain the metadata generated by the digital camera. Functions related to exif can be used without the GD Library.

You can use phpinfo. php to obtain the installation configuration of the GD Library:

Formats supported by GD

Format Read supported Supports writing Remarks
GIF TRUE TRUE Versions between GD 1.6 and GD 2.0.28 are not supported.
XBM TRUE TRUE PHP 4.0.1 supports reading and PHP 5.0.0 supports writing.
XPM TRUE FALSE PHP 4.0.1 supports reading. Unavailable on Windows. GD library to be bound with PHP
WebP TRUE TRUE GD 2.1 +, PHP 5.5 +

GD and image processing functions

? Gd_info-obtain information about the currently installed GD Library
? Getimagesize-get Image size
? Getimagesizefromstring-obtains image size information from a string
? Image_type_to_extension-get the file suffix of the image type
? Image_type_to_mime_type-obtains the MIME type of the image type returned by getimagesize, exif_read_data, exif_thumbnail, and exif_imagetype
? Image2wbmp-output the image to a browser or file in WBMP format
? Imageaffine-returns an image that has undergone affine transformation. the cropping area is optional.
? Imageaffinematrixconcat-Concat two matrices (as in doing sort ops in one go)
? Imageaffinematrixget-Return an image containing the affine tramsformed src image, using an optional clipping area
? Imagealphablending-set the mixed color mode of the image
? Imageantialias-whether to use the antialias function
? Imagearc-draw an elliptical arc
? Imagechar-draw a character horizontally
? Imagecharup-draw a character vertically
? Imagecolorallocate-assign color to an image
? Imagecolorallocatealpha-assign color + alpha to an image
? Imagecolorat-retrieve the color index value of a certain pixel
? Imagecolorclosest-obtains the index value of the color closest to the specified color.
? Imagecolorclosestalpha-gets the color closest to the specified color and transparency
? Imagecolorclosesthwb-gets the black-white index of the color closest to the given color
? Imagecolordeallocate-cancel image color allocation
? Imagecolorexact-retrieve the index value of the specified color
? Imagecolorexactalpha-obtains the index value of the specified color and transparency.
? Imagecolormatch-make the color of the color palette in an image better match the real color version.
? Imagecolorresolve-obtain the index value of the specified color or the nearest possible alternative value
? Imagecolorresolvealpha-gets the index value of the specified color + alpha or the closest possible alternative value
? Imagecolorset-set the color for the specified palette index
? Imagecolorsforindex-obtain the color of an index
? Imagecolorstotal-gets the number of colors in the palette of an image
? Imagecolortransparent-define a color as transparent
? Imageconvolution-apply for a 3x3 convolution matrix with coefficients p and offset
? Imagecopy-copy part of an image
? Imagecopymerge-copy and merge part of the image
? Imagecopymergegray-copy and merge part of an image in grayscale mode
? Imagecopyresampled-re-sample and copy part of the image and resize it
? Imagecopyresized-copy and resize some images
? Imagecreate-create a palette-based image
? Imagecreatefromgd2-create an image from The GD2 file or URL
? Imagecreatefromgd2part-create an image from the part of a given GD2 file or URL
? Imagecreatefromgd-create an image from the GD file or URL
? Imagecreatefromgif-creates a new image from a file or URL.
? Imagecreatefromjpeg-creates a new image from a file or URL.
? Imagecreatefrompng-creates a new image from a file or URL.
? Imagecreatefromstring-create an image from the image stream in the string
? Imagecreatefromwbmp-creates a new image from a file or URL.
? Imagecreatefromwebp-creates a new image from a file or URL.
? Imagecreatefromxbm-creates a new image from a file or URL.
? Imagecreatefromxpm-creates a new image from a file or URL.
? Imagecreatetruecolor-create a true color image
? Imagecrop-Crop an image using the given coordinates and size, x, y, width and height
? Imagecropauto-Crop an image automatically using one of the available modes
? Imagedashedline-draw a dotted line
? Imagedestroy-destroy an image
? Imageellipse-draw an ellipse
? Imagefill-region filling
? Imagefilledarc-draw an elliptical arc and fill it
? Imagefilledellipse-draw an ellipse and fill it
? Imagefilledpolygon-draw a polygon and fill it
? Imagefilledrectangle-draw a rectangle and fill it
? Imagefilltoborder-fill the area to the border of the specified color
? Imagefilter-apply a filter to the image
? Imageflip-Flips an image using a given mode
? Imagefontheight-get the font height
? Imagefontwidth-get the font width
? Imageftbbox-displays a text box in FreeType 2.
? Imagefttext-use FreeType 2 to write text to the image
? Imagegammacorrect-apply gamma correction to GD images
? Imagegd2-output GD2 images to a browser or file
? Imagegd-output the GD image to a browser or file
? Imagegif-output the image to a browser or file.
? Imagegrabscreen-Captures the whole screen
? Imagegrabwindow-Captures a window
? Imageinterlace-enable or disable interlace scan
? Imageistruecolor-check whether the image is a true color image
? Imagejpeg-outputs an image to a browser or file.
? Imagelayereffect-set the alpha color mixing sign to use the bound libgd layering effect
? Imageline-draw a line segment
? Imageloadfont-load a new font
? Imagepalettecopy-copy the palette from one image to another
? Imagepalettetotruecolor-Converts a palette based image to true color
? Imagepng-output the image to a browser or file in PNG format
? Imagepolygon-draw a polygon
? Imagepsbbox-a text box with the PostScript Type1 font
? Imagepsencodefont-change the character encoding vector in the font
? Imagepsextendfont-expanded or simplified font
? Imagepsfreefont-release the memory occupied by a PostScript Type 1 font
? Imagepsloadfont-load a PostScript Type 1 font from the file
? Imagepsslantfont-tilt a certain font
? Imagepstext-use the PostScript Type1 font to draw text strings on the image
? Imagerectangle-draw a rectangle
? Imagerotate-rotate an image from a given angle
? Imagesavealpha-set the flag to save the complete alpha channel information when saving the PNG image (opposite to a single transparent color)
? Imagescale-Scale an image using the given new width and height
? Imagesetbrush-set the paint brush image for the draw line
? Imagesetinterpolation-Set the interpolation method
? Imagesetpixel-draw a single pixel
? Imagesetstyle-set the draw line style
? Imagesetthickness-set the width of the draw line
? Imagesettile-set the texture for filling
? Imagestring-draw a line of strings horizontally
? Imagestringup-draw a line of string vertically
? Imagesx-get image width
? Imagesy-get image height
? Imagetruecolortopalette-convert a true color image to a color palette image
? Imagettfbbox-get the text range using the TrueType font
? Imagettftext-use the TrueType font to write text to the image
? Imagetypes-returns the image types supported by the current PHP version.
? Imagewbmp-output the image to a browser or file in WBMP format
? Imagewebp-output images in WebP format to a browser or file
? Imagexbm-output XBM images to browsers or files
? Iptcembed-embed binary IPTC data into a JPEG image
? Iptcparse-resolve the binary IPTC block to a single tag
? 20172wbmp-convert a JPEG image file to a WBMP image file
? Png2wbmp-convert a PNG image file to a WBMP image file

The GD library can be used in both Linux and Windows systems, and the functions are completely the same, but the graphic coordinates are offset. If the system is transplanted to each other, you must re-view the interface.

Draw Chinese characters on images


Generate verification code


Copyright Disclaimer: This article is an original article by the blogger Lang Yun studio and cannot be reproduced without the permission of the blogger.

The above describes how to use the GD library to generate a verification code in PHP to draw Chinese characters on the image, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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