|
楼主 |
发表于 2005 年 11 月 20 日 23:19:02
|
显示全部楼层
原创分享:初学者论坛签名程序 (申请精华)
现来演示:
具体设置参见:http://bbs.chuxuezhe.com/read.php?tid=107&page=e#a
源程序代码:- <?php
- ///////////////////////////////////////////////////
- ////////初学者论坛签名程序初级版///////////////////
- /////////////合成 by noonkeen//////////////////////
- ///////http://bbs.chuxuezhe.com////////////////////
- //now start
- Header("Content-type: image/GIF");
- ///////////////////////////////////////////////////
- //add a counter
- $Visited=array();
- if (!file_exists("Counter"))
- {
- for($i=0;$i<24;$i++)
- $Visited[$i]=0;
- $str=$Visited[0];
- for($i=1;$i<24;$i++)
- $str.=",$Visited[$i]";
- $fp=fopen("Counter","w");
- fputs($fp,$str);
- fclose($fp);
- }
- else
- {
- $fp=fopen("Counter","r");
- $str=trim(fgets($fp,100));
- $Visited=explode(",",$str);
- fclose($fp);
- }
- $Visited[date("G")]=intval($Visited[date("G")])+1;
- $str=$Visited[0];
- $max=intval($Visited[0]);
- for($i=1;$i<24;$i++)
- {
- $str.=",$Visited[$i]";
- if($max<=intval($Visited[$i]))
- $max=intval($Visited[$i]);
- }
- $fp=fopen("Counter","w");
- fputs($fp,$str);
- fclose($fp);
- $sum=0;
- for($i=0;$i<24;$i++)
- {
- $sum+=$Visited[$i];
- }
- //endcounter
- //////////////////////////////////////////////////////////////////////
- //start get the variable
- //for Chinese
- //from coolcode
- function gb2he($str) {
- $str = iconv("GB2312", "UTF-16BE", $str);
- for ($i = 0; $i < strlen($str); $i++,$i++) {
- $code = ord($str{$i}) * 256 + ord($str{$i + 1});
- if ($code < 128) {
- $output .= chr($code);
- } else if ($code != 65279) {
- $output .= "&#".$code.";";
- }
- }
- return $output;
- }
- //end Chinese
- //get name
- if (!isset($n)) {
- $n="Secret";
- }else{
- if (strlen($n)>12){
- $n="名字太长";
- }
- }
- //get birthday
- if (!isset($b)) {
- $b="Secret";
- }else{
- list ($month,$day,$year) = explode ('/', $b);
- if (!checkdate ($month,$day,$year)){
- $b="Wrong Format";
- }
- }
- //get his hobbies
- if (!isset($h)) {
- $h="Secret";
- }
- //get the QQ
- if (!isset($qq)) {
- $qq="No QQ";
- }else{
- if (!is_numeric($qq) ){
- $qq="Wrong Format";
- }
- }
- //get email
- if (!isset($e)) {
- $e="No email address";
- }
- //get motto
- if (!isset($m)) {
- $m="Secret";
- }else{
- if (strlen($m)>80){
- $m="太长了,居然有".strlen($m)."个汉字!应该控制在40个以内";
- }
- }
- //end get
- /////////////////////////////////////////////////////////////////////////
- //start create image
- $im = imageCreateFromGIF('sign01.gif');
- $black = ImageColorAllocate($im, 0,0,0);
- $white = ImageColorAllocate($im, 255,255,255);
- $red = ImageColorAllocate($im, 255,0,0);
- $blue = ImageColorAllocate($im, 0,0,255);
- //end define colors
- ////////////////////////////////////////////////////////////////////////
- //ip
- $ip = getenv('REMOTE_ADDR');
- ////////////////////////////////////////////////////////////////////////
- //day
- $today = getdate();
- $d1=date ("l");
- $d2=date ("m/j/Y");
- //define wday tips
- $wday = $today['wday'];
- if($wday==6 || $wday==0){
- $tips = "Enjoy the weekend!";
- }else{
- $tips = "Please go to work now!";
- }
- //end wday
- //end day
- //////////////////////////////////////////////////////////////////////////////
- //start English string
- imagestring($im,1,243,73,"you're from {$ip}",$black);
- imagestring($im,1,15,18,"{$d1} ",$black);
- imagestring($im,1,130,18,"{$d2} ",$black);
- imagestring($im,1,270,82,"{$tips}",$black);
- imagestring($im,1,65,80,"Refreshed Times:$sum",$ccfont);
- //end English string
- //////////////////////////////////////////////////////////////////////////
- //fontstyle
- $cfont="jdxsj.ttf";
- //////////////////////////////////////////////////////////////////////////
- //start sign
- $n=gb2he($n);
- $h=gb2he($h);
- $m1="";
- $m2="";
- if (strlen($m)<81){
- if (strlen($m)>26){
- for($i=0;$i<26;$i=$i+2){
- $m1=$m1.$m[$i].$m[$i+1];
- }
- for($i=26;$i<56;$i=$i+2){
- $m2=$m2.$m[$i].$m[$i+1];
- }
- for($i=56;$i<strlen($m);$i=$i+2){
- $m3=$m3.$m[$i].$m[$i+1];
- }
-
- }else{
- $m1=$m;
- }
- }
-
- $m1=gb2he($m1);
- $m2=gb2he($m2);
- $m3=gb2he($m3);
- //nickname
- ImageTTFText($im, 9, 0,292, 14, $blue, $cfont,$n);
- //hobby
- ImageTTFText($im, 8, 0,270, 42, $blue, $cfont,$h);
- //moto
- ImageTTFText($im, 8, 0,30, 40, $black, $cfont,$m1);
- ImageTTFText($im, 8, 0,10, 52, $black, $cfont,$m2);
- ImageTTFText($im, 8, 0,10, 64, $black, $cfont,$m3);
- //QQ
- imagestring($im,1,270,50,"{$qq} ",$blue);
- //email
- imagestring($im,1,280,62,"{$e} ",$blue);
- //birth
- imagestring($im,1,280,22,"{$b} ",$blue);
- //signature
- ImageTTFText($im, 8, 0,100,75, $black, $cfont,$n);
- //end sign
- //////////////////////////////////////////////////////////////////////////
- ImageGIF($im);
- ImageDestroy($im);
- ?>
复制代码 |
|