广

PHP编程

  • IOS开发
  • android开发
  • PHP编程
  • JavaScript
  • ASP.NET
  • ASP编程
  • JSP编程
  • Java编程
  • 易语言
  • Ruby编程
  • Perl编程
  • AJAX
  • 正则表达式
  • C语言
  • 编程开发

    解决GD中文乱码问题

    2018-10-18 20:39:19 次阅读 稿源:互联网
    零七广告
    今天仔细研究了下GD的一些相关技术,顺手也研究下GD中文乱码的问题。

      使用GD库输出中文字符串,调用imagestring是没有用的。需要使用imagettftext()函数。imagettftext函数的具体使用就参考手册啦。

      下面给个使用实例:

       
    $pic=imagecreate(250,30); 
    $black=imagecolorallocate($pic,0,0,0); 
    $white=imagecolorallocate($pic,255,255,255); 
    $font="C://WINDOWS//Fonts//simhei.ttf";  //这里的路进需要注意下,必须是字符的路径
    $str ='php'.iconv('gb2312','utf-8','面对对象')." www.phpobject.net"; 
    imagettftext($pic,10,0,10,20,$white,$font,$str);
          


        前面我给出一个简单的GD水印实例,只举例说明了使用图片如何水印的,这里给出一个文字水印的简单代码。

     
    <?php 
    $pic
    =imagecreate(250,30); 
    $black=imagecolorallocate($pic,0,0,0); 
    $white=imagecolorallocate($pic,255,255,255); 
    $font="C://WINDOWS//Fonts//simhei.ttf";  
    $str ='php'.iconv('gb2312','utf-8','面对对象')." www.phpobject.net"
    imagettftext($pic,10,0,10,20,$white,$font,$str);

    header("Content-type: image/jpeg");
    $filename='../src/images/photo.jpg';
    $im=imagecreatefromjpeg($filename);
    imagecopymerge($im,$pic,0,0,0,0,250,30,50);
    imagejpeg($im);
    ?>  
         

     

    零七网部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与零七网进行文章共享合作。

    零七广告
    零七广告
    零七广告
    零七广告