PHP Custom Size Verification Code method detailed _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
function Vcode ($num =4, $size =20, $width =0, $height =0) {
! $width && $width = $num * $size *4/5+5;
! $height && $height = $size + 10;
Removed 0 1 O l etc.
$str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";
$code = ";
for ($i =0; $i < $num; $i + +) {
$code. = $str [Mt_rand (0, strlen ($str)-1)];
}
Drawing images
$im = Imagecreatetruecolor ($width, $height);
Define the colors you want to use
$back _color = Imagecolorallocate ($im, 235, 236, 237);
$boer _color = Imagecolorallocate ($im, 118, 151, 199);
$text _color = imagecolorallocate ($im, Mt_rand (0,200), Mt_rand (0,120), Mt_rand (0,120));

Painting background
Imagefilledrectangle ($im, 0,0, $width, $height, $back _color);
Draw Border
Imagerectangle ($im, 0,0, $width-1, $height-1, $boer _color);
Draw interference Lines
for ($i =0; $i <5; $i + +) {
$font _color = imagecolorallocate ($im, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255));
Imagearc ($im, Mt_rand (-$width, $width), Mt_rand (-$height, $height), Mt_rand ($width), Mt_rand ($height), Mt_ Rand (0,360), Mt_rand (0,360), $font _color);
}
Draw interference points
for ($i =0; $i <50; $i + +) {
$font _color = imagecolorallocate ($im, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255));
Imagesetpixel ($im, Mt_rand (0, $width), Mt_rand (0, $height), $font _color);
}
Draw Verification Code
@imagefttext ($im, $size, 0, 5, $size +3, $text _color, ' C://WINDOWS//FONTS//SIMSUN.TTC ', $code);
Header ("cache-control:max-age=1, s-maxage=1, No-cache, must-revalidate");
Header ("Content-type:image/png");
Imagepng ($im);
Imagedestroy ($im);
}
?>

function Description and examples:
4 characters with a size of 20
Vcode (4,20);
?>

http://www.bkjia.com/PHPjc/327500.html www.bkjia.com true http://www.bkjia.com/PHPjc/327500.html techarticle Copy the code as follows: Php function Vcode ($num =4, $size =20, $width =0, $height =0) {! $width $width = $num * $size *4/5+5;! $height $hei ght = $size + 10; Removed 0 1 O L and other $str ...

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