{"id":407,"title":"php\u751f\u6210\u56fe\u7247\u9a8c\u8bc1\u7801","good":0,"bad":0,"hit":1311,"created_at":"2018-11-30 12:16:42","content":"
php\u751f\u6210\u56fe\u7247\u9a8c\u8bc1\u7801<\/p>
\u9700\u8981\u5f00\u542fgd\u6269\u5c55\uff0c\u4f46\u4e0d\u9700\u8981freetype\u652f\u6301<\/p>
<\/p>
\/**\n * \u751f\u6210\u56fe\u7247\u9a8c\u8bc1\u7801\n *\/\npublic function verify()\n{\n header("content-type:image\/png");\n $length = 4;\n $text = str_random($length);\n $key = 'img_verify_' . $text;\n $imgText = '';\n $imgW = 80;\n $imgH = 25;\n $imgRes = imagecreate($imgW, $imgH);\n imagecolorallocate($imgRes, 255, 255, 100);\n $color = imagecolorallocate($imgRes, 0, 0, 0);\n for ($i = 0; $i < $length; $i++) {\n $imgText .= ' ' . substr($text, $i, 1);\n }\n imagestring($imgRes, 5, 0, 5, $imgText, $color);\n for ($i = 0; $i < 100; $i++) {\n imagesetpixel($imgRes, rand(0, $imgW), rand(0, $imgH), $color);\n }\n imagepng($imgRes);\n imagedestroy($imgRes);\n $this->redis->setex($key, $this->config['expire_img_verify'], 1);\n}<\/pre>
<\/p>"}