欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

ImageString如何把中文字符输出到图片中?

程序员文章站 2024-01-08 12:14:52
...
试过利用iconv把中文字符转码然后输出,但还是乱码
    $s="你若输出,便是晴天";
    $ss=iconv("gb2312","utf8",$s);

    $im=ImageCreate(400,400);
    $black=ImageColorAllocate($im,0x00,0x00,0x00);
    ImageString($im,5,200,200,$ss,$black);
    Header('Content-Type:image/png');
    ImagePNG($im);

在网上搜了好久也没找到解决方法。 这个怎么破呢?

回复内容:

试过利用iconv把中文字符转码然后输出,但还是乱码

    $s="你若输出,便是晴天";
    $ss=iconv("gb2312","utf8",$s);

    $im=ImageCreate(400,400);
    $black=ImageColorAllocate($im,0x00,0x00,0x00);
    ImageString($im,5,200,200,$ss,$black);
    Header('Content-Type:image/png');
    ImagePNG($im);

在网上搜了好久也没找到解决方法。 这个怎么破呢?

imagestring使用点阵字库,如果你真的要用他的话需要自己构造中文的点阵字库,然后用imageloadfont来载入。
更推荐和常用的做法是使用imagettftext函数

输出中文最好使用 imagettftext()

imagestring基本无能为力

相关标签: php gd库