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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.