用PHP產生動態影像圖[轉自奧索]

來源:互聯網
上載者:User
很多人不瞭解    PHP 可以產生非HTML的資料.這是對產生影像圖非常有用的.可以從 database 產生一個簡單的廣告橫圖或更簡單只產生一個圖形按鈕 .
我用 TTF 字型在以下的範例中    
我通常取名作 'button.php3':
#######################################################
-----button.php3------
<?
    Header("Content-type: image/gif");
    if(!isset($s)) $s=11;
    $size = imagettfbbox($s,0,"fonts/TIMES.TTF",$text);
    $dx = abs($size[2]-$size[0]);
    $dy = abs($size[5]-$size[3]);
    $xpad=9;
    $ypad=9;
    $im = imagecreate($dx+$xpad,$dy+$ypad);
    $blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
    $black = ImageColorAllocate($im, 0,0,0);
    $white = ImageColorAllocate($im, 255,255,255);
    ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
    ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
    ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "fonts/TIMES.TTF", $text);
    ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "fonts/TIMES.TTF", $text);
    ImageGif($im);
    ImageDestroy($im);
?>
#######################################################
很重要一點是你不能在這檔案中放任何HTML tags.也不能有空白行在 <?和 ?> tag 之前或之後. 如果你用這段Script後看到一個不完整的影像, 表示你可能在PHP標籤以外誤打了字元.
以上的 script 可以由此文法在網頁中叫出來: <IMG SRC="button.php3?s=36&text=PHP+is+Cool">    
#######################################################
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.