免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1163 | 回复: 0
打印 上一主题 下一主题

[FreeBSD] 自制的FreeBSD Tips签名档(原创)! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-09-21 09:20 |只看该作者 |倒序浏览
不废话了,直接贴源代码吧。

(如果配合Apache的mod_rewrite,可以制作出绝对酷的效果!)


  1. <?php

  2. /****************************************************************************
  3. * tips.php
  4. * 将/usr/games/fortune freebsd-tips动态生成的tips转化成png图片!
  5. * 作者:DIrk Ye (dirk.ye AT gmail.com)
  6. * 版本:0.0.2
  7. * 更新:2004年09月21日
  8. * ChangeLog:
  9. * 2004年09月21日
  10. *   修改字体,替换文本中的TAB为空格,修改个别变量名称
  11. * 2004年09月20日
  12. *   Release 0.0.1
  13. ***************************************************************************/

  14. //error_reporting(E_ALL);
  15. error_reporting(0);

  16. $TIPS_FONT = 'fonts.ttf';

  17. // Get tips from fortune game
  18. $handle = popen('/usr/games/fortune freebsd-tips 2>;&1', 'r');
  19. if ($handle) {
  20.   $title = "FreeBSD Tips - http://dirk.pdx.cn (Dirk.Ye AT Gmail.com)";
  21.   $text  = str_replace("\t", "    ", fread($handle, 2096));

  22.   // We'll be outputting a png image
  23.   header("Content-type: image/png");
  24.   // Give a date in the past so that the browsers won't cache it.
  25.   header("Expires: Fri, 18 Jul 1980 05:00:00 GMT");

  26.   $fontsize = 9;
  27.   $txt_box1 = ImageTTFBBox($fontsize, 0, $TIPS_FONT, $title);
  28.   $txt_box2 = ImageTTFBBox($fontsize, 0, $TIPS_FONT, "$title\n$text");
  29.   $imwidth  = ($txt_box2[2] - $txt_box2[0]) + 2;
  30.   $imheight = ($fontsize) * 3 / 2 + ($txt_box2[3] - $txt_box2[5]);

  31.   $im = @imagecreate($imwidth, $imheight)
  32.     or die("Cannot Initialize new GD image stream");

  33.   $bgcolor = ImageColorAllocate($im, 255, 255, 255);
  34.   $ttcolor = ImageColorAllocate($im, 255, 100, 0);
  35.   $fgcolor = ImageColorAllocate($im, 5, 53, 126);
  36.   imagecolortransparent($im, $bgcolor);

  37.   imageTTFtext($im, $fontsize, 0, 1, $fontsize + 1, $ttcolor, $TIPS_FONT, $title);
  38.   imageline($im, 0, $fontsize * 3 / 2, $txt_box1[2] + 1, $fontsize * 3 / 2, $ttcolor);
  39.   imageTTFtext($im, $fontsize, 0, 1, $fontsize * 4, $fgcolor, $TIPS_FONT, $text);

  40.   imagepng($im);
  41.   imagedestroy($im);
  42. }
  43. @pclose($handle);

  44. ?>;
复制代码

[ 本帖最后由 Yerk 于 2006-5-14 10:34 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP