imagestring不支持中文,改用imagettftext

来源:互联网 发布:尚宝网络 编辑:程序博客网 时间:2024/05/19 18:41

想在图片上画点东西,手册上是imagestring,但是不支持中文,改用imagettftext,但是imagettftext需要引入字体,网上随便下载一下就可以了。

效果:


代码如下:

$width = 600;
$height = 650;
header("Content-type: image/gif; charset=utf-8");
$img = imagecreate($width, $height);
$bg_color = imagecolorallocate($img, 0, 0, 0);
$red = imagecolorallocate($img, 255, 0, 0);
$font = "./font/1.ttf";
$sting = '我的心就如这颗笛卡尔的情书!';
imagettftext($img, 20, 0, 5, 200, $red, $font, $sting);
$sting = '很遗憾不能再为您服务!如有疑问请联系管理员!';
imagettftext($img, 20, 0, 5, 300, $red, $font, $sting);
//imagestring ($img , 5 , 300 , 300 , $sting , $red );
for ($i = 0; $i <= 100; $i++) {
    for ($j = 0; $j <= 100; $j++) {
        $r = M_PI / 50 * $i * (1 - sin(M_PI / 50 * $j)) * 40;
        $x = $r * cos(M_PI / 50 * $j) * sin(M_PI / 50 * $i) + $width / 2;
        $y = -$r * sin(M_PI / 50 * $j) + $height / 6;
        imagesetpixel($img, $x, $y, $red);
    }
}

imagegif($img);
imagedestroy($img);

exit;




0 0