<?php
// Set the content-type
header("Content-type: image/png");// Create the image
$im = imagecreatetruecolor(400, 30);// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);// The text to draw
$text = '方正卡通简体...'; 
// Replace path by your own font path
$font = '方正卡通简体.ttf';
$text = iconv('gb2312','utf-8',$text);#Attention
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?> 

解决方案 »

  1.   

    首先'arial.ttf'不支持中文.
    当然会显示方框.方框不是乱码-_-!
      

  2.   

    字体的问题,window下有默认的中文字体SIMSUN.ttf,如果服务器是linux,就要下载相应的中文字体放到指定的目录里。
      

  3.   

    一楼的还是五星级的水平呢!汗!不支持FreeType什么字体也画不出来。
      

  4.   

    首先copy一个字体文件 如 simkai.ttf                $title="中文内容";
                    $title= iconv("gb2312","UTF-8",$title); 
    ImageTTFText($im,12,0,10,20,$black,"simkai.ttf",$title); 
      

  5.   

    joma925 
     
    等 级:
     发表于:2007-12-24 16:09:005楼 得分:0 
    字体的问题,window下有默认的中文字体SIMSUN.ttf,如果服务器是linux,就要下载相应的中文字体放到指定的目录里。 
     
    ///////////////////////////////////////////////////////////我当然知道要在图片上写字必须支持freetype,因为要用ttf函数。不过我没注意楼主说的仅仅"中文乱码",我也没试过不安装freetype用ttf函数写字生成的图片是什么样子。猜想应该是报一个"调用一个未定义的函数ImageTTFText()"的错误。而不仅仅是你说的什么字体也画不出来,要咬文嚼字的话你的回复也有问题。btw:你认为五个三角就应该知道每一个细节?找到这样机会贬低别人好凸显你的高明?你真高明,连freetype不支持,什么字体都画不出来这么高深的问题都知道。我自愧不如。某个细小知识点的疏漏并不能说明这个人很菜,把这些语法相关的东西背的很熟也不能说明你很牛。不知你是否还没有领悟到这一点。