If you want to use PHP's drawing function, you must first enable the function of this module. Just remove the comment in front of php_gd2.dll in php.ini.
Start drawing below:
Copy code The code is as follows:
session_start();
//Generate verification code image
Header("Content-type: image/PNG");
$im = imagecreate(44,18); // Draw a picture with specified width and height
$back = ImageColorAllocate($im, 245,245,245); //Define the background color
imagefill($im,0,0,$back); //Fill the background color into the image just drawn
$ vcodes = "";
srand((double)microtime()*1000000);
//Generate 4-digit number
for($i=0;$i<4;$i++){
$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // Generate random colors
$authnum=rand(1,9);
$vcodes.= $authnum;
imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
}
$_SESSION['VCODE'] = $vcodes;
for($i=0;$i<100;$i++) //Add interference pixels
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255) );
imagesetpixel($im, rand()%70, rand()%30, $randcolor); // Draw pixel function
}
ImagePNG($im);
ImageDestroy( $im);
?>
This is basically how it is implemented. In fact, if you watermark a picture, it is nothing more than writing into the picture. The principles are similar.
Where to use it directly
Fill in the name of this php file and you can use it.
http://www.bkjia.com/PHPjc/322029.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322029.htmlTechArticleIf you want to use PHP's drawing function, you must first enable the function of this module. Just remove the comment in front of php_gd2.dll in php.ini. Start drawing below: Copy the code The code is as follows...