国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 乌拉特前旗| 仁怀市| 芦溪县| 三亚市| 婺源县| 嘉兴市| 西乌珠穆沁旗| 黎川县| 南京市| 扎赉特旗| 伊金霍洛旗| 丹凤县| 兰西县| 苍梧县| 板桥市| 滦南县| 翼城县| 环江| 五峰| 垫江县| 荆州市| 楚雄市| 湖南省| 延寿县| 菏泽市| 张北县| 子洲县| 西宁市| 谷城县| 仙桃市| 九寨沟县| 武威市| 宁明县| 三穗县| 辽宁省| 称多县| 北辰区| 南江县| 尚义县| 湖北省| 澳门|