一個簡單的PHP圖形計數器____PHP

來源:互聯網
上載者:User

 

展示一個簡單的圖形計數器(本blog使用的計數器),代碼如下。

<?
Header("Content-type: image/PNG");
function CreateFile($filename,$content)
{            
        if (is_file ($filename))
        {
                @unlink ($filename);
        }
              $handle    = fopen ($filename,"w"); //開啟檔案指標,建立檔案
              /*
             檢查檔案是否被建立且可寫
              */
              if (!is_writable ($filename))
              {
                 die ("檔案:".$filename."不可寫,請檢查其屬性後重試。");
              }
              if (!fwrite ($handle,$content))
              {  //將資訊寫入檔案
                 die ("組建檔案".$filename."失敗。");
              }
            //  echo "<br>寫入檔案".$filename;
              fclose ($handle); //關閉指?
}
srand((double)microtime()*1000000);
$counterfile = 'blogcounter.txt';
$counter = @file_get_contents($counterfile );
$content = $counter+1;
@CreateFile($counterfile,$content);
$len = strlen($counter);
$im = imagecreate(($len+1)*10+5,15);
$black = ImageColorAllocate($im, 0,255,0);
$white = ImageColorAllocate($im, 255,255,255);
$green = ImageColorAllocate($im, 223,11,216);
//imagefill($im,45,18,$white);
imagefilledrectangle($im,0,0,($len+1)*10+5,20,$white);
//將計數器繪入圖片
@ImageTTFText($im, 8,0, 5,12, $green, "counter.ttf",$counter);
//imagestring($im, 4, 4, 1, $HTTP_GET_VARS['authnum'], $green);
for($i=0;$i<200;$i++) //加入幹擾象素
{
    imagesetpixel($im, rand()%50 , rand()%50 , $black);
}
ImagePNG($im);
ImageDestroy($im);
?>

附件:點擊下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.