PHP生成图片 中文就乱码 imagettftext -- 用 TrueType 字体向图像写入文本 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 iconvhttp://cn2.php.net/manual/en/book.iconv.php 本函数同时需要 GD 库和FreeType 库。 FreeType 下载地http://www.freetype.org/ 加入了字体属性,还是乱码。<?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'; 你这个PHP文件,以及之前的递交表单的文件保存为UTF-8格式比较好一些。然后再尝试iconv。 已经指定了字体的路径,我是在本地测试的,直接用的WINDOWS下面的FONT文件夹。 确定中文编码为utf-8确定你使用的字体是系统可以识别的字体.如果字体乱码,最好多换几种字体尝试. 你的这个代码文件保存编码和你html编码一致。最好指定下header 嗯,你看看ImageString的手册就知道了,第二个参数只能用内置或imageloadfont()载入的gdf字体,中文应该是不支持的,用楼上说的imagettftext和truetype字体即可,需要安装了gd和truetype库 <?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 = "请填写文本框内容,否则程序将无法生成图片文字";//判断文本框是否填写 //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); ?> wamp5 中的mysql 和我本机上安装的mysql是不是一个? 诡异。update执行不了 php如何删除某个文件 日期以图片形式显示 真他妈的怪,有PHP执行就不会成功,放到数据库直接运行能成功。 比较数据,只取符合要求的一条 PHP 连接MSSQL ,用UTF8提交到MSSQL,mssql 后台管理查询乱码问题? 正则问题请教 急:如何实现查询数据库多行、多列分页显示??? 关于 group by 的问题 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);
?>