php 使用imagettftext()函数出问题的原因
<?php header('Content-type: image/png'); $im = imagecreatetruecolor(400, 300); //创建画布 $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); //输出一个白色填充的矩形背景 // ////string iconv ( string $in_charset , string $out_charset , string $str ) ////将字符串 str 从 in_charset 转换编码到 out_charset。 // $text = iconv('gb2312','utf-8','show'); // ////设置字体 $font = 'C:\Windows\Fonts\msyh.ttc'; // imagettftext($im, 20, 0, 12, 21, $grey, $font, $text); //输出一个灰色字符串作为阴影 //imagettftext($im, 20, 0, 10, 20, $black, $font, $text); //输出一个黑色字符串 //ob_clean(); imagepng($im); imagedestroy($im);
设置字体的时候要写路径,不然就画不出来了