imagettftext -- 用 TrueType 字体向图像写入文本

解决方案 »

  1.   

    iconv
    http://cn2.php.net/manual/en/book.iconv.php
      

  2.   

    本函数同时需要 GD 库和FreeType 库。
      

  3.   

    FreeType 下载地http://www.freetype.org/
      

  4.   


    加入了字体属性,还是乱码。
    <?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';
      

  5.   

    你这个PHP文件,以及之前的递交表单的文件保存为UTF-8格式比较好一些。然后再尝试iconv。
      

  6.   

    已经指定了字体的路径,我是在本地测试的,直接用的WINDOWS下面的FONT文件夹。
      

  7.   

    确定中文编码为utf-8
    确定你使用的字体是系统可以识别的字体.如果字体乱码,最好多换几种字体尝试.
      

  8.   

    你的这个代码文件保存编码和你html编码一致。最好指定下header
      

  9.   

    嗯,你看看ImageString的手册就知道了,第二个参数只能用内置或imageloadfont()载入的gdf字体,中文应该是不支持的,
    用楼上说的imagettftext和truetype字体即可,需要安装了gd和truetype库
      

  10.   

    <?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);
      
     
     
     
    ?>