Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/2/10 6:48:44
PHP实现在图片中添加中文文字_[PHP教程]

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();
?>





If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759