PHP mobile phone number generation Image instance program

Source: Internet
Author: User
Tags current time rand strlen


PHP string processing-Survival Pictures of mobile phone numbers

 

The code is as follows: Copy code

<? Php
/// Convert the phone number into an image
// $ Str indicates the string to be displayed. $ rand indicates whether to enable the scrambling code.
Function str_to_image ($ str, $ w = 130, $ h = 25, $ rand = true)
    {
// Generate an 11-digit digital image
Header ("Content-type: image/png"); // tell the browser that the following data is an image instead of text
// Define the image width and height
$ Nwidth = $ w;
$ Nheight = $ h;
// Srand (double) microtime () * 1000000); // obtain the value of one second in the current time to one second in the execution time.
$ Randval = $ str; // 11 digits
$ Im = @ imagecreate ($ nwidth, $ nheight) or die ("Can't initialize new GD image stream"); // create an image
// Set the image color
$ Background_color = imagecolorallocate ($ im, 255,255,255); // match the color
$ Text_color = imagecolorallocate ($ im, 23, 14, 91 );
// Draw the image border
Imagefilledrectangle ($ im, $ nwidth-1, $ nheight-1, $ background); // rectangular area coloring
Imagerectangle ($ im, $ nwidth-1, $ nheight-1, $ background_color); // draw a rectangle
Imagestring ($ im, 8, 10, 4, $ randval, $ text_color); // draw a horizontal string
If ($ rand ){
// Add interference factors
For ($ I = 0; I I <260; $ I ++)
           {
$ Randcolor = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
Imagesetpixel ($ im, rand () % ($ nwidth-5), rand () % ($ nheight + 5), $ randcolor); // point
           }
       }
// Imagestring ($ im, 3,5, 5, "A Simple Text String", $ text_color );
// Imageinterlace ($ im, 1 );
Imagepng ($ im); // Create a png image
Imagedestroy ($ im); // End Chart type
    }

$ Str = '000000 ';
Echo str_to_image ($ str, $ w = 130, $ h = 25, $ rand = true)

Example 2

The code is as follows: Copy code


<? Php // do not leave blank lines
$ Id = $ _ GET [id];
Include ("admin/config. php ");
$ SQL = "select * from user where id = $ id ";
$ Data = mysql_fetch_array (mysql_query ($ SQL ));
$ P = SBC_DBC ($ data [Phone], 1 );
Function get_str ($ str, $ strlen = 16 ){
$ Str = stripslashes ($ str );
For ($ I = 0; $ I <$ strlen; $ I ++)
If (ord (substr ($ str, $ I, 1)> 0xa0) $ j ++;
If ($ j % 2! = 0) $ strlen ++;
$ Tmp_str = substr ($ str, 0, $ strlen );
Return $ tmp_str;
}
If ($ p <> ''){
// Generate a 5-digit digital image
Header ("Content-type: image/png"); // tell the browser that the following data is an image instead of text

// Define the image width and height
$ Nwidth = 120;
$ Nheight = 25;
$ Im = @ imagecreate ($ nwidth, $ nheight) or die ("Can't initialize new GD image stream"); // create an image

// Set the image color
$ Background_color = imagecolorallocate ($ im, 255,255,255); // match the color
$ Text_color = imagecolorallocate ($ im, 23, 14, 91 );

// Draw the image border
Imagefilledrectangle ($ im, $ nwidth-1, $ nheight-1, $ background); // rectangular area coloring
Imagerectangle ($ im, $ nwidth-1, $ nheight-1, $ background_color); // draw a rectangle

// Srand (double) microtime () * 1000000); // obtain the value of one second in the current time to one second in the execution time.
// $ Randval = rand ();
$ Randval = $ p; // 5-digit
Imagestring ($ im, 8, 10, 2, $ randval, $ text_color); // draw a horizontal string


// Add interference factors
// For ($ I = 0; $ I <478; $ I ++)
//{
// $ Randcolor = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255 ));
// Imagesetpixel ($ im, rand () % 100, rand () % 30, $ randcolor); // point
//}
// Imagestring ($ im, 3,5, 5, "A Simple Text String", $ text_color );
// Imageinterlace ($ im, 1 );
Imagepng ($ im); // Create a png image
Imagedestroy ($ im); // End Chart type

} Else {
Echo "<font size = 2> The Merchant did not enter the phone number </font> ";
}

?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.