Solution to the value of the verification code coordinate
Source: Internet
Author: User
About the verification code coordinate value --------------------------------------------- code ------------------------------------------------- $ image_width = 70; // set the image width about the verification code coordinate value
----------------------------------------------- Code -----------------------------------------------------
$ Image_width = 70; // set the image width
$ Image_height = 18; // set the image height
$ New_number = 1234;
$ Num_image = imagecreate ($ image_width, $ image_height); // Create a canvas
Imagecolorallocate ($ num_image, 255,255,255); // you can specify the canvas color.
For ($ I = 0; $ I $ Font = mt_rand (); // set a random font.
$ X = mt_rand () + $ image_width * $ I/4; // Set the X coordinate of the random character location
$ Y = mt_rand (1, $ image_height/4); // you can specify the Y coordinate of the random character location.
$ Color = imagecolorallocate ($ num_image, mt_rand (0,100), mt_rand (0,150), mt_rand (0,200); // set the character color
Imagestring ($ num_image, $ font, $ x, $ y, $ new_number [$ I], $ color); // horizontal output character
}
Imagepng ($ num_image); // generate an image in PNG format
Imagedestroy ($ num_image); // release image resources
---------------------------------------------- Code ------------------------
$ X = mt_rand () + $ image_width * $ I/4; // Set the X coordinate of the random character location
$ Y = mt_rand (1, $ image_height/4); // you can specify the Y coordinate of the random character location.
Why does $ x and $ y take this value? Is it random or regular? Please explain the rule.
------ Solution --------------------
This location can be obtained at will
However, in theory, we believe that the character of the verification code cannot exceed the line, otherwise it will not be recognized.
Generally, the location of the verification code should be random, and the random range should be maximized without exceeding the edge.
This reduces the chance of being cracked by machine scripts.
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