用ImageTTFText在图片上显示汉字的问题。

he8311 2008-12-14 11:22:44
在图片上显示汉字的问题。
ImageTTFText($img, $font, 0, 245, 13, $clrt, "f:/website/htdocs/tmp/font/SIMKAI.TTF", $str.":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)");
问题现象:经常要在页面上刷新10多次,才能看到正常的汉字显示,一般图片上的汉字都显示问号,这是怎么回事啊???
...全文
276 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zijian_Zhang 2008-12-14
  • 打赏
  • 举报
回复
[Quote=引用楼主 he8311 的帖子:]
ImageTTFText($img, $font, 0, 245, 13, $clrt, "f:/website/htdocs/tmp/font/SIMKAI.TTF", $str.":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)");
[/Quote]
感觉可能是后部分((round(10000*($datLst[$i]/$tot))/100))由些问题!!有时可以、有时不可以,这个问题比较怪,你试一下换个字体文件试一下。
he8311 2008-12-14
  • 打赏
  • 举报
回复
字符路径是要用绝对路径的啊
yongyuanjax 2008-12-14
  • 打赏
  • 举报
回复
感觉是字库的问题,你的这个路径有点怪....
he8311 2008-12-14
  • 打赏
  • 举报
回复
楼上的,已经用$str = iconv("GB2312", "UTF-8", $labLst[$i]);做了转换啊

function draw_img($datLst,$labLst,$clrLst,$a=250,$b=120,$v=20,$font=10)
{
$ox = 5+$a;
$oy = 35+$b;
$fw = imagefontwidth($font);
$fh = imagefontheight($font);
$n = count($datLst);//数据项个数
$w = 10+$a*2;
// $h = 10+$b*2+$v+($fh+2)*$n;
$h = 10+$b+$v+($fh+2)*$n;
// $h = 10+$v+($fh+2)*$n;
$img = imagecreate($w, $h);

//转RGB为索引色
for($i=0; $i<$n; $i++)
$clrLst[$i] = draw_getindexcolor($img,$clrLst[$i]);
$clrbk = imagecolorallocate($img, 0xff, 0xff, 0xff);
$clrt = imagecolorallocate($img, 0x00, 0x00, 0x00);

//填充背景色
imagefill($img, 0, 0, $clrbk);
//求和
$tot = 0;
for($i=0; $i<$n; $i++)
$tot += $datLst[$i];

$sd = 0;
$ed = 0;
$ly = 10+$b*2+$v;

for($i=0; $i<$n; $i++)
{
$sd = $ed;
$ed += $datLst[$i]/$tot*360;
//画圆饼
draw_sector3d($img, $ox-150, $oy-50, $a, $b, $v, $sd, $ed, $clrLst[$i]); //$sd,$ed,$clrLst[$i]);//可控制位置
//画标签
imagefilledrectangle($img, 235, $ly-250, 240+$fw, $ly+$fh-250, $clrLst[$i]);//可控制x、y位置
imagerectangle($img, 235, $ly-250, 240+$fw, $ly+$fh-250, $clrt);//可控制x、y位置
// imagestring($img, $font, 5+2*$fw, $ly, $labLst[$i].":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)", $clrt);
$str = iconv("GB2312", "UTF-8", $labLst[$i]);
//可控制x、y位置,控制显示字体
ImageTTFText($img, $font, 0, 245+2*$fw, $ly+13-250, $clrt, "f:/website/htdocs/tmp/font/simhei.ttf", $str.":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)");
$ly += $fh+2;
}

//输出图形
header("Content-type: image/png");
//输出生成的图片
// $imgFileName = "../temp/".time().".png";
// imagepng($img,$imgFileName);
imagepng($img);
//释放资源
imagedestroy($img);
}
iasky 2008-12-14
  • 打赏
  • 举报
回复
需要utf-8编码
he8311 2008-12-14
  • 打赏
  • 举报
回复
换了simkai.ttf字体,也是相同现象。偶尔可以显示,大部分时间不能显示。

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧