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

