php技術實現(xiàn)加載字體并保存成圖片
更新時間:2015年07月27日 17:55:07 作者:柒捌玖零
這篇文章主要介紹了php技術實現(xiàn)加載字體并保存成圖片,需要的朋友可以參考下
下面通過一段代碼給大家詳解介紹下php技術實現(xiàn)加載字體并保存成圖片。
// 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 = '字典網(wǎng)'; // 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);
以上代碼就可以完成加載字體并保存成圖片,希望大家會喜歡
相關文章
關于Laravel-admin的基礎用法總結(jié)和自定義model詳解
今天小編就為大家分享一篇關于Laravel-admin的基礎用法總結(jié)和自定義model詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10thinkphp5+layui實現(xiàn)的分頁樣式示例
這篇文章主要介紹了thinkphp5+layui實現(xiàn)的分頁樣式,結(jié)合實例形式詳細分析了thinkPHP5框架結(jié)合layui實現(xiàn)的分頁功能相關的配置、查詢等操作技巧,需要的朋友可以參考下2019-10-10PhpStorm的使用教程(本地運行PHP+遠程開發(fā)+快捷鍵)
這篇文章主要介紹了PhpStorm的使用教程(本地運行PHP+遠程開發(fā)+快捷鍵),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-03-03