Heim > Backend-Entwicklung > PHP-Tutorial > php 实现验证码制造

php 实现验证码制造

WBOY
Freigeben: 2016-06-13 12:21:23
Original
1037 Leute haben es durchsucht

php 实现验证码制作

先给看下 大致的效果

那么接下来的就直接贴代码吧

<span style="color: #000000;">php        </span><span style="color: #800080;">$image</span> = imagecreatetruecolor(100, 30); <span style="color: #008000;">//</span><span style="color: #008000;">创建画布</span>        <span style="color: #800080;">$imagecolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, 255, 255, 255);  <span style="color: #008000;">//</span><span style="color: #008000;">背景色</span><span style="color: #000000;">        imagefill(</span><span style="color: #800080;">$image</span>, 0, 0, <span style="color: #800080;">$imagecolor</span>);  <span style="color: #008000;">//</span><span style="color: #008000;">填充背景色</span>        <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++ ){                  <span style="color: #008000;">//</span><span style="color: #008000;">循环4位数</span>                <span style="color: #800080;">$fontsize</span> = 6<span style="color: #000000;">;        </span><span style="color: #800080;">$fontcolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, <span style="color: #008080;">rand</span>(0, 200), <span style="color: #008080;">rand</span>(0, 200), <span style="color: #008080;">rand</span>(0, 200<span style="color: #000000;">));        </span><span style="color: #800080;">$fontcontent</span> = <span style="color: #008080;">rand</span>(0, 9<span style="color: #000000;">);                </span><span style="color: #800080;">$x</span> = <span style="color: #800080;">$i</span>*100/4 + <span style="color: #008080;">rand</span>(5, 15<span style="color: #000000;">);        </span><span style="color: #800080;">$y</span> = <span style="color: #008080;">rand</span>(5, 10<span style="color: #000000;">);                imagestring(</span><span style="color: #800080;">$image</span>, <span style="color: #800080;">$fontsize</span>, <span style="color: #800080;">$x</span>, <span style="color: #800080;">$y</span>, <span style="color: #800080;">$fontcontent</span>, <span style="color: #800080;">$fontcolor</span><span style="color: #000000;">);    }                </span><span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++ ){              <span style="color: #008000;">//</span><span style="color: #008000;">循环 添加干扰点</span>                <span style="color: #800080;">$pointcolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, <span style="color: #008080;">rand</span>(50, 200), <span style="color: #008080;">rand</span>(50, 200), <span style="color: #008080;">rand</span>(50, 200<span style="color: #000000;">));                </span><span style="color: #800080;">$x</span> = <span style="color: #008080;">rand</span>(1, 99<span style="color: #000000;">);        </span><span style="color: #800080;">$y</span> = <span style="color: #008080;">rand</span>(1, 29<span style="color: #000000;">);                imagesetpixel(</span><span style="color: #800080;">$image</span>, <span style="color: #800080;">$x</span>, <span style="color: #800080;">$y</span>, <span style="color: #800080;">$pointcolor</span><span style="color: #000000;">);    }                </span><span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span>$i++){                <span style="color: #008000;">//</span><span style="color: #008000;">循环 添加干扰线    </span>                <span style="color: #800080;">$linecolor</span> = imagecolorallocate(<span style="color: #800080;">$image</span>, <span style="color: #008080;">rand</span>(100, 250), <span style="color: #008080;">rand</span>(100, 250), <span style="color: #008080;">rand</span>(100, 250<span style="color: #000000;">));                </span><span style="color: #800080;">$x1</span> = <span style="color: #008080;">rand</span>(1, 25<span style="color: #000000;">);        </span><span style="color: #800080;">$x2</span> = <span style="color: #008080;">rand</span>(50, 75<span style="color: #000000;">);                </span><span style="color: #800080;">$y1</span> = <span style="color: #008080;">rand</span>(1, 15<span style="color: #000000;">);        </span><span style="color: #800080;">$y2</span> = <span style="color: #008080;">rand</span>(15, 25<span style="color: #000000;">);                imageline(</span><span style="color: #800080;">$image</span>, <span style="color: #800080;">$x1</span>, <span style="color: #800080;">$y1</span>, <span style="color: #800080;">$x2</span>, <span style="color: #800080;">$y2</span>, <span style="color: #800080;">$linecolor</span><span style="color: #000000;">);    }                </span><span style="color: #008080;">header</span>("content-type:image/png"<span style="color: #000000;">);        imagepng(</span><span style="color: #800080;">$image</span><span style="color: #000000;">);        imagedestroy(</span><span style="color: #800080;">$image</span><span style="color: #000000;">);</span>?>
Nach dem Login kopieren

 

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage