Now more and more websites are beginning to use Chinese character verification code, both increase the intimacy of our countrymen, but also increase the difficulty of the machine to crack, here I will simply rough say ...
Create a background canvas
$image = imagecreatetruecolor (MB);
$background = Imagecolorallocate ($image, 255, 255, 255);
Imagefill ($image, 0, 0, $background);
Draw the jamming point
For ($i =0 $i < $i + +) {
$pixColor = imagecolorallocate ($image, rand (+), rand (+), rand (150, 240)) ;
$pixX = rand (190);
$pixY = rand (5);
Imagesetpixel ($image, $pixX, $pixY, $pixColor);
Draw Interference Line
4 Horizontal line for
($i =0 $i < 5 $i + +) {
$lineColor = imagecolorallocate ($image, Rand, Rand), Rand (5 0));
$lineX 1 = 0;
$lineX 2 =;
$lineY 1 = ($i + 1) *;
$lineY 2 = ($i + 1) *;
Imageline ($image, $lineX 1, $lineY 1, $lineX 2, $lineY 2, $lineColor);
10 vertical lines for
($i =0 $i < $i + +) {
$lineColor = imagecolorallocate ($image, Rand, Rand), RA nd (m));
$lineX 1 = ($i + 1) *;
$lineX 2 = ($i + 1) *;
$lineY 1 = 0;
$lineY 2 =;
Imageline ($image, $lineX 1, $lineY 1, $lineX 2, $lineY 2, $lineColor);
Draw Chinese Characters
$text = Array (' zhi ', ' zi ', ' flower ', ' open ');
For ($i =0 $i < 4 $i + +) {
$textColor = imagecolorallocate ($image, Rand, Rand), Rand (a));
$textX = $i * +;
$textY = rand (a);
Imagettftext ($image, Rand (a), $textX, $textY, $textColor, "/library/fonts/Chinese imitation. Ttf", $text [$i]);
}
Note here that the font file must support Chinese
Encoding to use UTF-8,GBK Chinese remember to turn? "Iconv function can help you."
Output image
Header ("Content-type:image/png");
Imagepng ($image);
Destroying resources
After a rough do it, the Chinese verification code is also displayed, of course, the general Web site when the use of a Chinese character library seed, from the inside randomly out a specific number of Chinese characters display, and finally is recorded to the session to verify.
The above mentioned is the entire content of this article, I hope you can enjoy.