国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP實現在圖片中添加中文文字

2024-05-04 23:04:22
字體:
來源:轉載
供稿:網友

<?php
/*
注意:需要gd庫支持,需要iconv支持(php5已經包含不用加載)
*version 1.0
*@author sanshi(叁石)
*qq: 35047205
*msn: [email protected]
*create 2005/10/20
在圖片中添加中文文字
*/
 /*
  param $image   圖象資源
  param size     字體大小
  param angle    字體輸出角度
  param showx    輸出位置x坐標
  param showy    輸出位置y坐標
  param font    字體文件位置
  param content  要在圖片里顯示的內容
 */
class showchinatext
{
 var $text='你好';
 var $font='fs.ttf';
 var $angle=0;
 var $size=50;
 var $showx=100;
 var $showy=100;
 function showchinatext($showtext='')
 {
   $this->text=!isset($showtext)?$showtext:$this->text;
  //exit();
  $this->show();
 }
 function createtext($instring)
 {
   $outstring="";
   $max=strlen($instring);
   for($i=0;$i<$max;$i++)
   {
   $h=ord($instring[$i]);
   if($h>=160 && $i<$max-1)
   {
              $outstring.="&#".base_convert(bin2hex(iconv("gb2312","ucs-2",substr    ($instring,$i,2))),16,10).";";
              $i++;
   }
   else
   {
              $outstring.=$instring[$i];
   }
   }
  return $outstring;
 }
 function createjpeg()
 {}
 function show()
 {
  //輸出頭內容
  header( "content-type: image/png");
  //建立圖象
  $image = imagecreate(400,300);
  //定義顏色
  $red = imagecolorallocate($image,255,0,0);
  $white = imagecolorallocate($image,255,255,255);
  $black=imagecolorallocate($image,0,0,0);
  //填充顏色
  imagefilledrectangle($image,0,0,200,200,$red);
  //顯示文字
  $txt=$this->createtext($this->text);
  //寫入文字
  imagettftext($image,$this->size, $this->angle, $this->showx, $this->showy,$white,$this->font,$txt);
  //imagestring($image,5,50,10,$txt,$white);
  //顯示圖形
  imagejpeg($image);
  imagedestroy($image);
 }
}
//本類,并沒有經過很好的考慮,只是簡單的進行了封裝,以后有機會,可能跟原來的圖片類整合
?>
<?php
//使用示例
$s = new showchinatext();
?>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 弥勒县| 延边| 利津县| 沂水县| 农安县| 根河市| 阿瓦提县| 永春县| 贡觉县| 徐闻县| 甘泉县| 高陵县| 开阳县| 江永县| 黄浦区| 祥云县| 郯城县| 蒲江县| 广平县| 扶绥县| 讷河市| 习水县| 宜君县| 丰城市| 乌鲁木齐县| 浏阳市| 宾川县| 安丘市| 新民市| 康马县| 常德市| 黄山市| 塘沽区| 施秉县| 张家港市| 集安市| 读书| 寿光市| 宁阳县| 枞阳县| 运城市|