欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2015年07月27日 17:55:07   作者:柒捌玖零  
這篇文章主要介紹了php技術實現(xiàn)加載字體并保存成圖片,需要的朋友可以參考下
下面通過一段代碼給大家詳解介紹下php技術實現(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);  

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

相關文章

最新評論