在图形中使用指定字体
使用imagettftext()函数,可以向图片输出字符的同时,也可指定输出字符所使用的字体,另外imagettftext()函数也可以根据参数,输出不同角度的字符串。下面演示imagettftext()函数的使用方法,
<?php
//创建一个新图形
$image = imagecreate(400,200);
//设置背景,分配颜色
$bgColor = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
//指定要使用的字体文件
$font = “simhei.ttf”;
//用图形中输出字符串
imagettftext($image,20,0,10,50,$black,$font,”imagettftext()”);
imagettftext($image,20,90,50,150,$black,$font,”imagettftext()”);
imagettftext($image,20,180,300,100,$black,$font,”imagettftext()”);
imagettftext($image,20,60,150,150,$black,$font,”imagettftext()”);
imagettftext($image,20,360,200,50,$black,$font,”imagettftext()”);
//输出图形
header(‘Content-type: image/png’);
imagepng($image);
//释放资源
imagedestroy($image);
?>