- 论坛徽章:
- 0
|
不废话了,直接贴源代码吧。
(如果配合Apache的mod_rewrite,可以制作出绝对酷的效果!)
- <?php
- /****************************************************************************
- * tips.php
- * 将/usr/games/fortune freebsd-tips动态生成的tips转化成png图片!
- * 作者:DIrk Ye (dirk.ye AT gmail.com)
- * 版本:0.0.2
- * 更新:2004年09月21日
- * ChangeLog:
- * 2004年09月21日
- * 修改字体,替换文本中的TAB为空格,修改个别变量名称
- * 2004年09月20日
- * Release 0.0.1
- ***************************************************************************/
- //error_reporting(E_ALL);
- error_reporting(0);
- $TIPS_FONT = 'fonts.ttf';
- // Get tips from fortune game
- $handle = popen('/usr/games/fortune freebsd-tips 2>;&1', 'r');
- if ($handle) {
- $title = "FreeBSD Tips - http://dirk.pdx.cn (Dirk.Ye AT Gmail.com)";
- $text = str_replace("\t", " ", fread($handle, 2096));
- // We'll be outputting a png image
- header("Content-type: image/png");
- // Give a date in the past so that the browsers won't cache it.
- header("Expires: Fri, 18 Jul 1980 05:00:00 GMT");
- $fontsize = 9;
- $txt_box1 = ImageTTFBBox($fontsize, 0, $TIPS_FONT, $title);
- $txt_box2 = ImageTTFBBox($fontsize, 0, $TIPS_FONT, "$title\n$text");
- $imwidth = ($txt_box2[2] - $txt_box2[0]) + 2;
- $imheight = ($fontsize) * 3 / 2 + ($txt_box2[3] - $txt_box2[5]);
- $im = @imagecreate($imwidth, $imheight)
- or die("Cannot Initialize new GD image stream");
- $bgcolor = ImageColorAllocate($im, 255, 255, 255);
- $ttcolor = ImageColorAllocate($im, 255, 100, 0);
- $fgcolor = ImageColorAllocate($im, 5, 53, 126);
- imagecolortransparent($im, $bgcolor);
- imageTTFtext($im, $fontsize, 0, 1, $fontsize + 1, $ttcolor, $TIPS_FONT, $title);
- imageline($im, 0, $fontsize * 3 / 2, $txt_box1[2] + 1, $fontsize * 3 / 2, $ttcolor);
- imageTTFtext($im, $fontsize, 0, 1, $fontsize * 4, $fgcolor, $TIPS_FONT, $text);
- imagepng($im);
- imagedestroy($im);
- }
- @pclose($handle);
- ?>;
复制代码
[ 本帖最后由 Yerk 于 2006-5-14 10:34 编辑 ] |
|