最近,闲的没事干,看到Rain在做这个项目,于是我也想坐一个争取比Rain好(不服)[Rain此项目链接:网页链接]

首先我们要用到的是1个API:IP归属地查询API(总不能自建IP库吧)

我们要用到的有:1.底图一张2.文字(ttf文字)

放写好的源代码:

[php] connect('127.0.0.1', 6379); $check = $redis->exists("count"); if($check){ $redis->incr("count"); $count = $redis->get("count"); } //获取浏览器 function browse\_info() { if (!empty($\_SERVER\['HTTP\_USER\_AGENT'\])) { $br = $\_SERVER\['HTTP\_USER\_AGENT'\]; if (preg\_match('/MSIE/i', $br)) { $br = 'MSIE'; } else if (preg\_match('/Firefox/i', $br)) { $br = 'Firefox'; } else if (preg\_match('/Chrome/i', $br)) { $br = 'Chrome'; } else if (preg\_match('/Safari/i', $br)) { $br = 'Safari'; } else if (preg\_match('/Maxthon/i', $br)) { $br = '遨游'; } else if (preg\_match('/IE/i', $br)) { $br = 'IE'; } else if (preg\_match('/Opera/i', $br)) { $br = 'Opera'; } else { $br = 'Other'; } return $br; } else { return 'unknow'; } } //获取运营商 function getIsp($ip) { $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; $ipinfo=json\_decode(file\_get\_contents($url)); if($ipinfo->code=='1'){ return false; } $isp = $ipinfo->data->isp; return $isp; } //打开图片 $dst\_path = 'yuantu.png';//原图,修改为你原图的路径 $dst = imagecreatefromstring(file\_get\_contents($dst\_path)); $font = './XXX.ttf';//字体路径 //获取刚才生成的数据 $browse= browse\_info(); $ip= get\_real\_ip(); $isp= getIsp($ip); $city=getCity("$ip"); $os=get\_os(); $count0="$count 次"; //设定字体颜色 $black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色 //添加字体 imagefttext($dst,28,0,122,50,$black,$font,$ip); imagefttext($dst,26,0,151,102,$black,$font,$city); imagefttext($dst,28,0,155,153,$black,$font,$os); imagefttext($dst,28,0,181,205,$black,$font,$isp); imagefttext($dst,28,0,182,255,$black,$font,$browse); imagefttext($dst,28,0,182,302,$black,$font,$count0); //输出图片 list($dst\_w, $dst\_h, $dst\_type) = getimagesize($dst\_path); header('Content-Type: image/png'); imagepng($dst); imagedestroy($dst); ?> [/php]

注意,本程序需要Redis支持(如果你的主机不支持Redis,请尝试删除或修改Redis部分)

效果图:


广告
广告正在加载中...
暂不开放评论,如对本文有任何疑问,请联系i#mr-wu.top(#替换为@)