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

WBOY
Release: 2016-06-06 20:48:45
Original
1447 people have browsed it

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

<code class="lang-php">    $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);
</code>
Copy after login
Copy after login

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

回复内容:

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

<code class="lang-php">    $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);
</code>
Copy after login
Copy after login

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

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

<code><?php header("Content-type: image/jpeg");
$im = imagecreatetruecolor(100,50);
$textcolor = imagecolorallocate($im,255,255,255);
$font = "C://windows/fonts/simhei.ttf";
$text='中国';
$text = mb_convert_encoding($text,'UTF-8','GB2312');
imagettftext($im,10,4,20,20,$textcolor,$font,$text);
imagejpeg($im);
?>
</code>
Copy after login

输出中文最好使用 imagettftext()

imagestring基本无能为力

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!