最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php 生成文字png圖片的代碼

 更新時間:2011年04月17日 21:54:25   作者:  
使用GD生成文字圖片是php一項比較常用的功能,筆者今天介紹的是生成文字png圖片的函數(shù)。需要的朋友可以參考下。
復制代碼 代碼如下:

<?
/*
php生成文字png圖片,可以使用如下方式調用函數(shù):
http://www.yourdomian.com/text_png.php3?msg=helloworld+class&rot=15&size=48&font=fonts/ARIAL.TTF
*/
Header("Content-type: image/png");
class textPNG {
var $font = 'fonts/TIMES.TTF'; //默認字體. 相對于腳本存放目錄的相對路徑.
var $msg = "undefined"; // 默認文字.
var $size = 24;
var $rot = 0; // 旋轉角度.
var $pad = 0; // 填充.
var $transparent = 1; // 文字透明度.
var $red = 0; // 在黑色背景中...
var $grn = 0;
var $blu = 0;
var $bg_red = 255; // 將文字設置為白色.
var $bg_grn = 255;
var $bg_blu = 255;
function draw() {
$width = 0;
$height = 0;
$offset_x = 0;
$offset_y = 0;
$bounds = array();
$image = "";
// 確定文字高度.
$bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W");
if ($this->rot < 0) {
$font_height = abs($bounds[7]-$bounds[1]);
} else if ($this->rot > 0) {
$font_height = abs($bounds[1]-$bounds[7]);
} else {
$font_height = abs($bounds[7]-$bounds[1]);
}
// 確定邊框高度.
$bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg);
if ($this->rot < 0) {
$width = abs($bounds[4]-$bounds[0]);
$height = abs($bounds[3]-$bounds[7]);
$offset_y = $font_height;
$offset_x = 0;
} else if ($this->rot > 0) {
$width = abs($bounds[2]-$bounds[6]);
$height = abs($bounds[1]-$bounds[5]);
$offset_y = abs($bounds[7]-$bounds[5])+$font_height;
$offset_x = abs($bounds[0]-$bounds[6]);
} else {
$width = abs($bounds[4]-$bounds[6]);
$height = abs($bounds[7]-$bounds[1]);
$offset_y = $font_height;;
$offset_x = 0;
}
$image = imagecreate($width+($this->pad*2)+1,$height+($this->pad*2)+1);
$background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
$foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu);
if ($this->transparent) ImageColorTransparent($image, $background);
ImageInterlace($image, false);
// 畫圖.
ImageTTFText($image, $this->size, $this->rot, $offset_x+$this->pad, $offset_y+$this->pad, $foreground, $this->font, $this->msg);
// 輸出為png格式.
imagePNG($image);
}
}
$text = new textPNG;
if (isset($msg)) $text->msg = $msg; // 需要顯示的文字
if (isset($font)) $text->font = $font; // 字體
if (isset($size)) $text->size = $size; // 文字大小
if (isset($rot)) $text->rot = $rot; // 旋轉角度
if (isset($pad)) $text->pad = $pad; // padding
if (isset($red)) $text->red = $red; // 文字顏色
if (isset($grn)) $text->grn = $grn; // ..
if (isset($blu)) $text->blu = $blu; // ..
if (isset($bg_red)) $text->bg_red = $bg_red; // 背景顏色.
if (isset($bg_grn)) $text->bg_grn = $bg_grn; // ..
if (isset($bg_blu)) $text->bg_blu = $bg_blu; // ..
if (isset($tr)) $text->transparent = $tr; // 透明度 (boolean).
$text->draw();
?>

相關文章

  • PHP中spl_autoload_register函數(shù)的用法總結

    PHP中spl_autoload_register函數(shù)的用法總結

    本文是對PHP中spl_autoload_register函數(shù)的用法進行了詳細的總結介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2013-11-11
  • php生成隨機密碼的幾種方法

    php生成隨機密碼的幾種方法

    使用PHP開發(fā)應用程序,尤其是網(wǎng)站程序,常常需要生成隨機密碼,如用戶注冊生成隨機密碼,用戶重置密碼也需要生成一個隨機的密碼。
    2011-01-01
  • 2010年最新PHP類的精髓歸納

    2010年最新PHP類的精髓歸納

    2010年最新PHP類的精髓歸納,需要的朋友可以參考下。
    2010-03-03
  • PHP的偽隨機數(shù)與真隨機數(shù)詳解

    PHP的偽隨機數(shù)與真隨機數(shù)詳解

    這篇文章主要介紹了PHP的偽隨機數(shù)與真隨機數(shù)詳解,本文首先講解了真隨機數(shù)和偽隨機數(shù)的相關概念,并給出了比用mt_rand()函數(shù)產(chǎn)生更好的偽隨機數(shù)的一段例子代碼,需要的朋友可以參考下
    2015-05-05
  • PHP超全局變量實現(xiàn)原理及代碼解析

    PHP超全局變量實現(xiàn)原理及代碼解析

    這篇文章主要介紹了PHP超全局變量實現(xiàn)原理及代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-09-09
  • PHP與Web頁面的交互示例詳解一

    PHP與Web頁面的交互示例詳解一

    這篇文章主要介紹了PHP與Web頁面的交互示例詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • php一行代碼獲取文件后綴名實例分析

    php一行代碼獲取文件后綴名實例分析

    這篇文章主要介紹了php一行代碼獲取文件后綴名的方法,以實例形式較為詳細的分析了其中涉及的函數(shù)和原理,并補充了三種常用的獲取文件后綴名的方法,需要的朋友可以參考下
    2014-11-11
  • phpexcel導出excel的顏色和網(wǎng)頁中的顏色顯示不一致

    phpexcel導出excel的顏色和網(wǎng)頁中的顏色顯示不一致

    關于phpexcel導出顏色的一些問題,用phpexcel做導出的excel的顏色怎么和網(wǎng)頁中的顏色顯示不一致呢,接下來將詳細介紹解決方法
    2012-12-12
  • mongodb和php的用法詳解

    mongodb和php的用法詳解

    在本篇文章中小編給大家分享了關于mongodb和php的用法以及相關知識點,需要的朋友們學習下。
    2019-03-03
  • 在php中實現(xiàn)限流ip次數(shù)以及允許部分ip訪問的代碼示例

    在php中實現(xiàn)限流ip次數(shù)以及允許部分ip訪問的代碼示例

    這篇文章給大家介紹了如何在php中實現(xiàn)限流ip次數(shù)以及允許部分ip訪問,文中通過代碼示例給大家介紹的非常詳細,對大家的學習具有一定的參考價值,需要的朋友可以參考下
    2023-12-12

最新評論

苍溪县| 长宁县| 宁都县| 加查县| 拜城县| 宁津县| 昭苏县| 瓮安县| 聂拉木县| 东城区| 内江市| 巴塘县| 临桂县| 元江| 泊头市| 平谷区| 子长县| 海南省| 青神县| 巴彦县| 漳浦县| 孟连| 南召县| 大洼县| 类乌齐县| 潍坊市| 盐池县| 于都县| 林芝县| 德惠市| 惠水县| 通榆县| 望谟县| 巴里| 石景山区| 黔江区| 凤台县| 南涧| 保靖县| 大丰市| 栾川县|