php 加载字体 并保存成图片

WBOY
リリース: 2016-06-23 13:29:55
オリジナル
703 人が閲覧しました

[php]  view plain copy

 

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

 

如果想保存图可以用下面代码

 

[html]  view plain copy

 

    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);   

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!