效果:
代码:
<?php /** * 说明:一张显示QQ在线状态的图片,上边可以自定义最长四个文字,彩色为在线,灰度为不在线 * 比如:一张灰度的,上书“技术支持”的图片 * 一张彩色的,上书“客户服务”的图片 * 参数:?qq=123456&string=客户服务 // qq用来判断是否在线,string是写的文字 * 注意:文字最长四个字且不会居中 * 作者:upall,http://upall.cn/ * 日期:22:59 2011年9月13日 */ $id = '123456'; $string = '在线客服'; //$font = '../Signature/msyh.ttf'; // 字体,这里采用“微软雅黑”,请自备,路径可自行修改 $font = 'simsun.ttc'; // 宋体,微软雅黑没有了柔化效果挺难看的 $allowedHost = array('upall.cn'); // 用于防盗链 $data[0] = 'R0lGODlhSgAWAOYAAAAAAM/j76XT9Y2bpY2Njmpub+bw9lVVVXqt08Xb51mNs4uluuXy/LnDyiUlJdvp8bzT4Z+yvs3h7pLF6+zs7JSmsTw8PXl6ehwcHKjC1bXd+aWqrt7e3tjj6l1fYOb39+Ht9bTL2tLS0/j7/Wuewu30+YK226Wlpcbd7IqTmMXO04OEhGGRs3R0dPj4+P///7W2t5mZmaq8x7nU5pSttcPW4oi84W+jyX6Gi3V/hpfK76y/ytTm8N7m9+/3/8zMzKW5xpSUlGZmZp6mq73W5Nzv/c7n+ZyuuWSYvnF2eXemycvZ4oSEjLvI0IzA5ZrN8qqqqqezu67Czv///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEHAFMALAAAAABKABYAAAf/gFNFGgKFhoeIiYqLjI2OhRpFU0YaDCOXmJmam5ydnp+glwwaRgIlp6ipqqusra6vsKsCT6wNQg4OGB4wBgaxv8DBp086vcYGGwcWuRjNSR3H0dLT1NXW0zoT0SoWFhwvAC8czUPQ1+fo6ccTEyDu7gW44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ACH5BAEHAGMALAAAAABKABYAAAf/gGNcLSuFhoeIiYqLjI2OhS1cY2ItFT2XmJmam5ydnp+glxUtVSs1p6ipqqusra6vsKsrWKxLVyG4DksXCrG+v8CnWFgKxcYvDhq4y0BQM8bQ0dLT1NXWxlhD0QcOQEVNAE1FuAnO1+fo6dBDQzPu7lcaV+AJ4bkoMe/6+/z9/v8A3Q0RsA+XN3DiQmjQEKVEwIcQI+oTwOKCxQsxjISQkKLjgwcSFApxcbGkyZMoU6pcaZHFlJJFThAgIOGjBAkzTyxBwbKnz58lp7y8GISJByYcOiiFUIBHAQ4bYgCdStXkFBExsibQ0MGDDhBgiSDJMSIHki74sqpdy7at27dw/9+KwJoVSIgrNJgwAQFDho+/PhDIMPElruHDiNuK8KIWlxUlX7c4UYEADBgECFR0mRAmsefPbb1QCUA6BJAFW8A2oUAZMwIDKigcaUC6tu3buHPr3p2byo4wwCccgAFlS48mThgwwGxAuewnwKNLn069uvXr1Xf8Bv4FQxIMLhRkMcCDgYEcynmYmAAdu/v38KXvsPCj/o8IOFJ811KkCw8ZAPIgGwoN2GfggQgmqOCCC1pAn30LRCBhBAtksAAENmQIwQ1HfMDghyCGiKAFO3hYHwpRCHHDDUIcEMUBQkghxQ0HECjijTgi+IEFKHjxQQMNPIHCBEROgMIHQxaJwigTQDbp5JNQRinllFF+4MUBY0xgwQBcdunll2CGKeaYZJbJpQUHQBEIADs='; // 在线 // 初始化 if (isset($_GET['qq'])){ $id = (int)(trim($_GET['qq'])); } if (isset($_GET['string'])){ $string = urldecode(trim($_GET['string'])); } $status = 'http://webpresence.qq.com/getonline?Type=1&'.$id.':'; // 腾讯提供的查询在线状态的“接口” $status = @file_get_contents($status); // 值类似:online[0]=1; $status = (int)substr($status,-2,1); // 取分号前的值 if ($status != 1 && $status != 0 ){ // 腾讯只提供了“在线”“不在线”这两个状态 exit('Error Status !'); } // 防盗链 if (empty($_SERVER['HTTP_REFERER'])){ $fromHost = ''; }else{ $fromUrl = $_SERVER['HTTP_REFERER']; preg_match_all("/(.+\.)?(\w+\.\w+)/",$fromUrl,$fromHost); // 取顶级域名 $fromHost = $fromHost[2][0]; } if (!in_array($fromHost,$allowedHost)){ // 非许可的域名访问时输出固定的文字“禁止盗链” $string = '禁止盗链'; } // 生成图像 $data = $data[$status]; $data = base64_decode($data); $image = @imagecreatefromstring($data); $textcolor = @imagecolorallocate($image, 0, 0, 0); //背景,字体大小,倾斜,坐标X,坐标Y,字体文件,写入的文字 @imagettftext($image,9,0,22,16,$textcolor,$font,$string); // 输出 header('content-type:image/gif'); imagegif($image); ?>
<完>