一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - php 生成文字png圖片的代碼

php 生成文字png圖片的代碼

2019-11-21 13:48PHP教程網 PHP教程

使用GD生成文字圖片是php一項比較常用的功能,筆者今天介紹的是生成文字png圖片的函數。需要的朋友可以參考下。

代碼如下:


<? 
/* 
php生成文字png圖片,可以使用如下方式調用函數: 
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(); 
?> 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 人妖三级| 久久亚洲高清观看 | 99视频一区 | 暖暖的免费观看高清视频韩国 | 天天舔天天操天天干 | 国产成人福利美女观看视频 | 午夜无码国产理论在线 | 日剧整部剧护妻狂魔免费观看全集 | 369看片网| 韩国漂亮美女三级在线观看 | 色综合久久天天综合观看 | 亚洲福利一区二区精品秒拍 | 男人使劲躁女人视频免费 | 手机能看的黄色网站 | 亚洲四虎| 窝窝影院午夜色在线视频 | 国产情侣自拍网 | a韩剧| 青草福利视频 | 草草国产成人免费视频 | 阿 好深 快点 老师受不了 | 日韩高清一区 | jj视频免费观看 | 狠狠综合久久综合网站 | 国产乱妇无码大片在线观看 | 欧美日韩不卡视频 | 久久天天躁狠狠躁夜夜躁 | ova巨公主催眠1在线观看 | 国产清纯白嫩大学生正在播放 | 亚洲精品第一国产综合 | 亚洲另类第一页 | 99热精品久久 | 日本免费在线观看视频 | 日韩高清在线观看 | 4hu永久地域网名入口 | 91高清在线视频 | 国产高清亚洲 | 黑人草 | 午夜免费无码福利视频麻豆 | 日本天堂网 | 日本一区二区在线不卡 |