首頁  >  文章  >  後端開發  >  PHP載入字體並儲存成圖片實例分享

PHP載入字體並儲存成圖片實例分享

*文
*文原創
2017-12-28 15:49:081423瀏覽

本文主要介紹了php技術實作載入字體並儲存成圖片,需要的朋友可以參考下。希望對大家有幫助。

下面透過一段程式碼給大家詳解介紹下php技術實作載入字體並儲存成圖片。

// 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 = '字典网'; 
// 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);

相關推薦:

很強的 PHP 圖片處理類別

php 圖片縮圖的實作方法

php 圖片上傳

#

以上是PHP載入字體並儲存成圖片實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn