search
Homephp教程php手册PHP实现在图片中添加中文文字

/*
注意:需要gd库支持,需要iconv支持(php5已经包含不用加载)
*version 1.0
*@author sanshi(叁石)
*QQ: 35047205
*MSN: sanshi0815@tom.com
*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   {
   $h=ord($instring[$i]);
   if($h>=160 && $i   {
              $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);
 }
}
//本类,并没有经过很好的考虑,只是简单的进行了封装,以后有机会,可能跟原来的图片类整合
?>
//使用示例
$s = new showChinaText();
?>



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.