imagettftext -- 用 TrueType 字体向图像写入文本
解决方案 »
- 关于论坛屏蔽回帖问题?求帮忙
- php如何制作比例图形?
- checkbox变成神仙了?困扰我好多天了
- 有没有必要对PDO进行封装?
- Warning: session_module_name() [function.session-module-name]: A session is acti
- GROUP BY 语句怎么用php输出来类
- 关于文件上传
- 有谁改过discuz论坛吗,我想在下面加一个广告条
- 大家来讨论一下,完成功能只用一个页面只用一个文件的好呢,还是分解成N个页面的好呢?这样会影响速度吗?
- 配置完Apache+PHP后!出现了这个问题!请问怎样解决呢?
- mktime() expects parameter 6 to be long, string given问题
- 安装mysql server时发生了冲突
http://cn2.php.net/manual/en/book.iconv.php
加入了字体属性,还是乱码。
<?php
// set up image
$height = 200;
$width = 200;
$im = ImageCreateTrueColor($width, $height);
$white = ImageColorAllocate ($im, 255, 255, 255);
$blue = ImageColorAllocate ($im, 0, 0, 64);
$wenben = $_POST['text11'];
//判断文本框是否填写
if ( (empty($wenben)) )
{
echo '请填写文本框内容,否则程序将无法生成图片文字';
exit;
}
/* if ( $wenben == '' )
{
echo '请填写文本内容';
exit;
}*/
//设置字体
putenv('GDFONTPATH=C:\WINDOWS\Fonts');
$fontname = 'Arial';
// draw on image
ImageFill($im, 0, 0, $blue);
ImageLine($im, 0, 0, $width, $height, $white);
ImageString($im, $fontname, 50, 150, $wenben, $white);// output image
Header ('Content-type: image/png');
ImagePng ($im);
// clean up
ImageDestroy($im);
?>
//设置字体
putenv('GDFONTPATH=C:\WINDOWS\Fonts');
$fontname = 'Arial';
确定你使用的字体是系统可以识别的字体.如果字体乱码,最好多换几种字体尝试.
用楼上说的imagettftext和truetype字体即可,需要安装了gd和truetype库
// set up image
$height = 200;
$width = 200;
$im = ImageCreateTrueColor($width, $height);
$white = ImageColorAllocate ($im, 255, 255, 255);
$blue = ImageColorAllocate ($im, 0, 0, 64);
$wenben = "请填写文本框内容,否则程序将无法生成图片文字";
//判断文本框是否填写
//if ( (empty($wenben)) )
// {
// echo '请填写文本框内容,否则程序将无法生成图片文字';
// exit;
// }
/* if ( $wenben == '' )
{
echo '请填写文本内容';
exit;
}*/
// draw on image
ImageFill($im, 0, 0, $blue);
ImageLine($im, 0, 0, $width, $height, $white);
//putenv('GDFONTPATH=C:\WINDOWS\Fonts');
//$font="simfang.tiff";
$font="simkai.ttf";//imagettftext($im, 20,0, 50, 150, $white ,$font,iconv('UTF-8','UTF-8',$wenben));
imagettftext($im, 20,0, 50, 150, $white ,$font,$wenben);// output image
Header ('Content-type: image/png');
ImagePng ($im);
// clean up
ImageDestroy($im);
?>