- 论坛徽章:
- 0
|
我的个人网站发布啦,嘿嘿
好的,本来是支持truetype,后来这个空间不支持truetype,所以我改了代码,没有做什么测试:)
- /**
- * @name : checkImage
- * @author : ShenKong <shenkong@php.net>;
- * @version : $id
- * @package : checkImage
- * @copyright: ShenKong (http://www.openphp.cn)
- */
- function checkImage($info)
- {
- global $session;
- $bgLength = $info["bgLength"];
- $bgWidth = $info["bgWidth"];
- $fontSize = $info["fontSize"];
- $length = $info["length"];
- $image = imagecreatetruecolor($bgLength, $bgWidth);
- $white = imagecolorallocate($image, 0xAA, 0xAA, 0xAA);
- imagefilledrectangle($image, 0, 0, $bgLength, $bgWidth, $white);
- for ($i = 0; $i < 400; $i++)
- {
- imagestring($image, 1, rand(0, $bgLength), rand(0, $bgWidth) , "*", randColor($image));
- }
-
- $str = md5(mt_rand());
- $str = strtoupper($str);
- //$str = str_replace(array("I", "1", "8", "B", "0", "D"), "", $str);
- $str = substr($str, 0, $length);
- $string = $str;
- $session->;set("checkImageString", $string);
- $w = ($bgLength - ($length - 1) * 3) / $length;
- for ($i = 0; $i < $length; $i++)
- {
- imagestring($image, $fontSize, mt_rand($w * $i + 3 * $i, $w * ($i + 1) + 3 * $i - 12), mt_rand(0, $bgWidth - 14), substr($str, $i, 1), fontRandColor($image));
- }
-
- // 设置白色为透明
- //imagecolortransparent($this->;image, $white);
- header("Content-Type: image/png");
- imagepng($image);
- }
-
- function fontRandColor($image)
- {
- return imagecolorallocate($image, mt_rand(0, 200), mt_rand(0, 100), mt_rand(0, 150));
- }
-
- function randColor($image)
- {
- return imagecolorallocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255));
- }
复制代码 |
|