当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


PHP imageloadfont()用法及代码示例

imageloadfont()函数是PHP中的内置函数,用于加载新字体。支持GDF字体,可以从此处下载。

用法:

int imageloadfont( string $file )

参数:该函数接受一个包含字体的单个参数$file。


返回值:此函数返回的字体标识符始终大于5,以避免与内置字体或错误时为FALSE冲突。

下面给出的程序说明了PHP中的imageloadfont()函数:

程序1(在图纸上书写):

<?php 
  
// Create a new image instance 
$im = imagecreatetruecolor(105, 15); 
  
// Prepare the colors 
$black = imagecolorallocate($im, 0, 0, 0); 
$white = imagecolorallocate($im, 255, 255, 255); 
  
// Make the background white 
imagefilledrectangle($im, 0, 0, 700, 250, $white); 
  
// Load the gd font from local folder 
// and write 'GeeksforGeeks' 
$font = imageloadfont('./Hollow_8x16_LE.gdf'); 
imagestring($im, $font, 0, 0, 'GeeksforGeeks', $black); 
  
// Scale the image bigger 
$im1 = imagescale($im, 700); 
  
// Output to browser 
header('Content-type:image/png'); 
imagepng($im1); 
imagedestroy($im); 
?>

输出:

程序2(在图像上书写):

<?php 
  
// Create an image instance 
$im = imagecreatefrompng( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Prepare the red color 
$red = imagecolorallocate($im, 255, 0, 0); 
  
// Load the gd font from local folder and write 'GeeksforGeeks' 
$font = imageloadfont('./Hollow_8x16_LE.gdf'); 
imagestring($im, $font, 200, 100, 'GeeksforGeeks', $red); 
  
// Output to browser 
header('Content-type:image/png'); 
imagepng($im); 
imagedestroy($im); 
?>

输出:

参考: https://www.php.net/manual/en/function.imageloadfont.php



相关用法


注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | imageloadfont() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。