亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Interference elements (points) in PHP development verification code tutorial

In the previous section, we have finished displaying 4 random numbers in the canvas.

The code is as follows:

<?php
    //第一步 創(chuàng)建一個畫布
    $image = imagecreatetruecolor(100, 30); //創(chuàng)建一個寬為100高為30的黑色圖像
    $bgcolor = imagecolorallocate($image, 255, 255, 255); //為圖像分配顏色
    imagefill($image,0,0,$bgcolor); //給黑色的背景圖像分配白色
    

    //第二步,在這個圖像上實現(xiàn)數(shù)字
    for($i=0;$i<4;$i++){
        $fontsize = 6; //字體大小

        $fontcolor = imagecolorallocate($image,rand(1,120),rand(1,120),rand(1,120));
        //設置字體的顏色 顏色我們給一個隨機的值,畫布為白色,0到120之間,顏色為深色
        $fontcontent = rand(0,9); //設置內容是一個隨機數(shù)

        //現(xiàn)在需要把這個隨機數(shù)添加到畫布上去
        $x = ($i*100/4)+rand(5,10);
        $y = rand(5,10);
        imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
    }
    //輸出圖像
    header("content-type:image/png");
    imagepng($image);

    //銷毀資源
    imagedestroy($img);

?>

Next we will add interference based on the above code. Element

Similarly we use a for loop to add points to add 200 points

for($i=0;$i<200;$i++){

/ /First we set the color of the point

$pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
//Set where the point is placed in the image Up
imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor);

}

Let’s take a look at the complete code:

<?php
    //第一步 創(chuàng)建一個畫布
    $image = imagecreatetruecolor(100, 30); //創(chuàng)建一個寬為100高為30的黑色圖像
    $bgcolor = imagecolorallocate($image, 255, 255, 255); //為圖像分配顏色
    imagefill($image,0,0,$bgcolor); //給黑色的背景圖像分配白色
    

    //第二步,在這個圖像上實現(xiàn)數(shù)字
    for($i=0;$i<4;$i++){
        $fontsize = 6; //字體大小

        $fontcolor = imagecolorallocate($image,rand(1,120),rand(1,120),rand(1,120));
        //設置字體的顏色 顏色我們給一個隨機的值,畫布為白色,0到120之間,顏色為深色
        $fontcontent = rand(0,9); //設置內容是一個隨機數(shù)

        //現(xiàn)在需要把這個隨機數(shù)添加到畫布上去
        $x = ($i*100/4)+rand(5,10);
        $y = rand(5,10);
        imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
    }
    
    //設置干擾元素 點
    for($i=0;$i<200;$i++){
        //首先我們設置點的顏色
        $pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
        //設置點放在圖像的什么位置上
        imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor);
    }
    
    //輸出圖像
    header("content-type:image/png");
    imagepng($image);

    //銷毀資源
    imagedestroy($img);

?>


Continuing Learning
||
<?php //第一步 創(chuàng)建一個畫布 $image = imagecreatetruecolor(100, 30); //創(chuàng)建一個寬為100高為30的黑色圖像 $bgcolor = imagecolorallocate($image, 255, 255, 255); //為圖像分配顏色 imagefill($image,0,0,$bgcolor); //給黑色的背景圖像分配白色 //第二步,在這個圖像上實現(xiàn)數(shù)字 for($i=0;$i<4;$i++){ $fontsize = 6; //字體大小 $fontcolor = imagecolorallocate($image,rand(1,120),rand(1,120),rand(1,120)); //設置字體的顏色 顏色我們給一個隨機的值,畫布為白色,0到120之間,顏色為深色 $fontcontent = rand(0,9); //設置內容是一個隨機數(shù) //現(xiàn)在需要把這個隨機數(shù)添加到畫布上去 $x = ($i*100/4)+rand(5,10); $y = rand(5,10); imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor); } //設置干擾元素 點 for($i=0;$i<200;$i++){ //首先我們設置點的顏色 $pointcolor = imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200)); //設置點放在圖像的什么位置上 imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor); } //輸出圖像 header("content-type:image/png"); imagepng($image); //銷毀資源 imagedestroy($img); ?>
submitReset Code