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

php 生成文字png圖片的代碼

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

<?
/*
php生成文字png圖片,可以使用如下方式調(diào)用函數(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; // 旋轉(zhuǎn)角度.
var $pad = 0; // 填充.
var $transparent = 1; // 文字透明度.
var $red = 0; // 在黑色背景中...
var $grn = 0;
var $blu = 0;
var $bg_red = 255; // 將文字設(shè)置為白色.
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; // 旋轉(zhuǎn)角度
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();
?>

相關(guān)文章

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

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

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

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

    使用PHP開發(fā)應(yīng)用程序,尤其是網(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ù)的相關(guān)概念,并給出了比用mt_rand()函數(shù)產(chǎn)生更好的偽隨機數(shù)的一段例子代碼,需要的朋友可以參考下
    2015-05-05
  • PHP超全局變量實現(xiàn)原理及代碼解析

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

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

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

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

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

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

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

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

    mongodb和php的用法詳解

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

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

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

最新評論

鹿泉市| 大厂| 武宁县| 和平区| 冀州市| 安丘市| 桃园县| 三亚市| 宣汉县| 池州市| 会宁县| 通道| 津南区| 嘉善县| 米易县| 绍兴县| 抚顺市| 新泰市| 柳河县| 顺昌县| 和平县| 江安县| 深泽县| 卓尼县| 宾川县| 临夏市| 仁布县| 新昌县| 固阳县| 丰原市| 咸宁市| 磐安县| 景洪市| 延津县| 裕民县| 沅陵县| 工布江达县| 益阳市| 潼南县| 余庆县| 清河县|