In the previous article, I brought you "How to draw polygons, arcs and ellipses in PHP? (Detailed graphic explanation)", which introduces in detail how to draw graphics in PHP. In this article, we will take a look at how we generate graphic verification codes in PHP. I hope everyone has to help!
Through our previous article on image drawing in PHP, we can use the knowledge to make an extension, which is the graphical verification we often use on daily login pages. code, how is the graphic verification code formed? If you want to learn how to make the graphic verification code, first let's take a look at how to draw text in PHP.
Drawing text
The functions we commonly use to draw text are:
imagechar()
: Draw a character horizontally
imagecharup()
: Draw a character vertically Characters
#imagestring(): Draw a line of string horizontally
imagestringup(): Draw a line of string vertically
imagettftext(): Use TrueType font to image Write text in
imagechar(resource $image, int $font, int $x, int $y, string $c, int $color)
imagettftext(resource $image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text)
##This is completed through the imagettftext() function Drawing of text.
Draw graphics verification codeAfter the previous learning of drawing text and images, we can then draw graphics using the knowledge we have learned before. Drawing of verification codes, we often encounter graphical verification codes in our login interface, so let's take a look at how to create it.
First, let’s take a look at the final effect:
To achieve such an effect, you need to go through some steps:
The first step is to prepare the canvas we need, which is to create the canvas. Then prepare the string we want to generate, draw the interference pattern on the canvas, then output the image, and finally release the resources.
The example is as follows:
Recommended study:《
PHP video tutorialThe above is the detailed content of How to draw graphical verification code through PHP?. For more information, please follow other related articles on the PHP Chinese website!