PHP通过GD库输出中文(简单方法)

需要在UTF8页面上才能使用!

// 建立一幅 100X30 的图像
$im = imagecreate(100, 30);

// 白色背景和蓝色文本
$font="C://WINDOWS//Fonts//simhei.ttf"; // linux 不知道如何处理.
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// 写入中文
imagettftext($im, 20, 0, 10, 20, $textcolor, $font, "中文");

// 输出图像
header("Content-type: image/png");
imagepng($im);

Leave a Reply