php实现加载字体并保存
程序员文章站
2022-03-10 11:08:04
...
本篇文章主要介绍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技术实现加载字体并保存成图片_PHP
-
完美实现wordpress禁止文章修订和自动保存的方法,wordpress自动保存_PHP教程
-
php实现粘贴截图并完成上传功能_PHP
-
yii2搭建完美后台并实现rbac权限控制案例教程,yii2rbac_PHP教程
-
php使用simplexml_load_file加载XML文件并显示XML的方法
-
jQuery向下滚动即时加载内容实现的瀑布流效果_PHP
-
PHP实现301重定向并通知搜索引擎的代码_PHP教程
-
php同时使用session和cookie来保存用户登录信息的实现代码,sessioncookie_PHP教程
-
php实现input输入框失去焦点自动保存输入框的数据