按照教程写了如下创建图像的代码
<?php
$height=200;
$width=200;
$im=imagecreatetruecolor($width,$height);
$white=imagecolorallocate($im,255,255,255);
$blue=imagecolorallocate($im,0,0,64);
imagefill($im,0,0,$blue);
imageline($im,0,0,$width,$height,$white);
imagestring($im,4,50,150,'sales',$white);
header('content-type:image/png');
imagepng($im);
imagedestroy($im);
?>但是为什么网页上会呈现一片乱码呢?已经扩展了php_gd2.dll这个库了
php的版本的5.05

解决方案 »

  1.   


    $width=540;
    $height=340;
    $pic = imagecreate ($width,$height );
    $bgColor = imagecolorallocate ( $pic, 255, 255, 255 );
    $fontColor1= imagecolorallocate ($pic, 0, 0, 0 );
    $fontColor2= imagecolorallocate ($pic, 255, 0, 0 );
    $font = "simsun.ttf";//指定服务器字体路径
    imagettftext($pic, $fontSize, 0, 0,16, $fontColor1, $font, 'www.bingfengsa.com 南瓜屋提供' );
    header("Content-type: image/jpeg" );
    imagejpeg($pic);
    imagedestroy($pic);
      

  2.   

    header("Content-type: image/jpeg" );
    这个是关键
      

  3.   

    你的代码在我这没有问题!我的页面utf-8。 
      

  4.   

    以上的回答都不能解决该问题
    一下是错误显示
    ?PNG  IHDRȀȈ":9ɀƉDATx?휉rꈔF២V^?????T6?9g"i?
      

  5.   

    你的代码我这里运行正常啊,你的页面调整成utf8,如果还出错就估计你的gd库没有开启了
      

  6.   

    在我的机器上测试没有问题,编码都不用改,随便建个记事本,然后把代码考进去,就可以了。
    倒是如果我把header("content-type:image/png");这句去了的话,就乱码了!
      

  7.   

    测试通过,中文无乱码 header("Content-type: image/jpeg");
    $width=540;
    $height=340;
    $pic = imagecreate ($width,$height );
    $bgColor = imagecolorallocate ( $pic, 255, 255, 255 );
    $fontColor1= imagecolorallocate ($pic, 0, 0, 0 );
    $fontColor2= imagecolorallocate ($pic, 255, 0, 0 );
    $font = "simsun.ttf";//指定服务器字体路径
    $fontSize = 20 ;
    imagettftext($pic, $fontSize, 0, 10,30, $fontColor1, $font, 'www.bingfengsa.com 南瓜屋提供' );imagejpeg($pic);
    imagedestroy($pic);
      

  8.   

    关键两点
    $font = "simsun.ttf";//当前目录下一定要有 simsun.ttf 这个字体
    $fontSize = 20 ; //字的大小设置也必须有
      

  9.   

    补充一下,PHP文件本身必须用记事本保存为UTF-8编码才会显示,否则要嘛乱码,要吗出错显示不了!
      

  10.   

    我也发一个中文显示的代码,以供参考!如下:header ("Content-type: image/png");    
    $str="中文字体显示";    
    //$pic=imagecreatefrompng("background.png"); 
    $width=540;
    $height=340;
    $pic = imagecreatetruecolor($width,$height );
    $color=imagecolorallocate($pic,255,0,0);
    $back=imagecolorallocate($pic,0,0,0);
     imagettftext($pic,12, -90, 250, 150,$color,"C:/WINDOWS/Fonts/simhei.ttf",$str);    
     imagepng($pic);  
     imagedestroy($pic);
      

  11.   


    顺道说说2者区别:imagecreate和imagecreatetruecolor的区别:imagecreate 建立基于GD1库的256色图象,其背景色是以第一个颜色设置为准!
    imagecreatetruecolor建立基于GD2库的真彩色图象,其背景色默认为黑色,但是可以用imagefill进行填充,改变颜色!