国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php技術(shù)實現(xiàn)加載字體并保存成圖片

2024-05-04 23:38:08
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php技術(shù)實現(xiàn)加載字體并保存成圖片,需要的朋友可以參考下

下面通過一段代碼給大家詳解介紹下php技術(shù)實現(xiàn)加載字體并保存成圖片。

 

 
  1. // Set the content-type  
  2. header("Content-type: image/png");  
  3.  
  4. // Create the image  
  5. $im = imagecreatetruecolor(400, 100);  
  6.  
  7. // Create some colors  
  8. $white = imagecolorallocate($im, 255, 255, 255);  
  9. $grey = imagecolorallocate($im, 128, 128, 128);  
  10. $black = imagecolorallocate($im, 0, 0, 0);  
  11. imagefilledrectangle($im, 0, 0, 399, 100, $white);  
  12.  
  13. // The text to draw  
  14. $text = '字典網(wǎng)';  
  15. // Replace path by your own font path  
  16. $font = 'fontName.ttf';  
  17.  
  18. // Add some shadow to the text  
  19. //imagettftext($im, 60, 0, 11, 21, $grey, $font, $text);  
  20.  
  21. // Add the text  
  22. imagettftext($im, 60, 0, 0, 70, $black, $font, $text);  
  23.  
  24. // Using imagepng() results in clearer text compared with imagejpeg()  
  25. imagepng($im);  
  26. imagedestroy($im);  

如果想保存圖可以用下面代碼

 

 
  1. ob_start();  
  2. imagejpeg($im);  
  3. $img = ob_get_contents();  
  4. ob_end_clean();  
  5. $size = strlen($img);  
  6.  
  7. $fp2=@fopen('tst.jpg'"a");  
  8. fwrite($fp2,$img);  
  9. fclose($fp2);  

以上代碼就可以完成加載字體并保存成圖片,希望大家會喜歡

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 乐至县| 黄浦区| 旬阳县| 沙田区| 大埔区| 如东县| 韶关市| 喀喇沁旗| 宜城市| 深水埗区| 凤山市| 宁城县| 万山特区| 桐城市| 文成县| 湾仔区| 社旗县| 锡林郭勒盟| 鄂伦春自治旗| 乐清市| 搜索| 峡江县| 且末县| 闸北区| 武鸣县| 双柏县| 禹州市| 台中县| 阿图什市| 凤冈县| 乌兰县| 芜湖市| 贵州省| 长葛市| 故城县| 达拉特旗| 渑池县| 普洱| 北宁市| 白朗县| 古交市|