PHP prints digital code in picture form

Source: Internet
Author: User

Define output as Image type
$n = 10;
Variable $n is the number of displayed digits

Using the above method, get the number of visitors and assign value to the variable $str1 (Cheng)
$str 1= $count;
$str 2 = "";
Number of digits if not enough $n, 0 in front
$len 1 = strlen ($str 1);
for ($i =1; $i <= $n; $i + +) {
$str 2 = "0". $str 2;
};
Get $n bit 0
$len 2 = strlen ($str 2);
Count the number of digits visited
$dif = $len 2-$len 1;
$rest = substr ($str 2, 0, $DIF);
$string = $rest. $str 1;
Number of digits if not enough $n, 0 in front
For ($i =0 $i <= $n-1; $i + +) {
$str [$i]=substr ($string, $i, 1);
};
Storing each digit in an array
$font = 4;
Define font Size
$im = Imagecreate ($n *11-1,16);
New Image
$black = Imagecolorallocate ($im, 0,0,0);
$white = Imagecolorallocate ($im, 255,255,255);
Define Color
Imagefill ($im, 0,0, $black);
Set the background of the counter to black
Imagestring ($im, $font, 1,0, $str [0], $white);
For ($i =1 $i <= $n-1; $i + +) {
Imageline ($im, $i *11-1,0, $i *11-1,16, $white);
Imagestring ($im, $font, $i *11+1,0, $str [$i], $white);
};
Writes each bit to the image and separates it with a vertical bar
Imagegif ($im);
Image output
Imagedestroy ($im);
Releasing the image

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.