php以图形方式显示中文,指定ttf字库

 1 <?php
 2 header("Content-Type:image/png");
 3 $img=imagecreatetruecolor(400,300);
 4 // imagejpeg($img);
 5 // imagejpeg($img,"./img/copy_img01.jpg",10);
 6 $color1=imagecolorallocate($img,100,100,100);
 7 $color2=imagecolorallocate($img,255,0,0);
 8 $str="北京欢迎你!";
 9 imagefill($img,0,0,$color1);
10 // imagestring($img,5,0,0,$str,$color2);
11 $fontfile="F:\phpStudy\WWW\myweb\FZXBSJW.ttf";
12 imagettftext($img,24,0,100,100,$color2,$fontfile,$str);
13 imagepng($img);
14 imagedestroy($img);
15 // header("Content-Type:text/html");
16 // echo "gave over!";
第13行imagepng($img)必须有,中文字体路径必须是绝对路径。
posted @ 2022-08-14 22:15  paoPaoLong_liu  阅读(186)  评论(0)    收藏  举报