您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php实现加载字体并保存

2024/3/15 10:50:55发布22次查看
本篇文章主要介绍php实现加载字体并保存,感兴趣的朋友参考下,希望对大家有所帮助。
下面通过一段代码给大家详解介绍下php技术实现加载字体并保存成图片,具体如下:
// set the content-type header("content-type: image/png"); // create the image $im = imagecreatetruecolor(400, 100); // create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 100, $white); // the text to draw $text = '字典网'; // replace path by your own font path $font = 'fontname.ttf'; // add some shadow to the text //imagettftext($im, 60, 0, 11, 21, $grey, $font, $text); // add the text imagettftext($im, 60, 0, 0, 70, $black, $font, $text); // using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im);
如果想保存图可以用下面代码
ob_start(); imagejpeg($im); $img = ob_get_contents(); ob_end_clean(); $size = strlen($img); $fp2=@fopen('tst.jpg', "a"); fwrite($fp2,$img); fclose($fp2);
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php判断及获取文件扩展名的几种方法
php中缓存技术的原理、特点及用法
php中那些经常混淆的知识点
以上就是php实现加载字体并保存的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product