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


PHP imagestring()用法及代码示例

imagestring()函数是PHP中的内置函数,用于水平绘制字符串。此函数在给定位置绘制字符串。

用法:

bool imagestring( $image, $font, $x, $y, $string, $color )

参数:该函数接受上述和以下所述的六个参数:


  • $image:imagecreatetruecolor()函数用于创建给定尺寸的空白图像。
  • $font:此参数用于设置字体大小。使用latin2编码的内置字体可以是1、2、3、4、5或使用imageloadfont()函数注册的其他字体标识符。
  • $x:此参数用于保存左上角的x坐标。
  • $y:此参数用于保留左上角的y坐标。
  • $string:此参数用于保存要写入的字符串。
  • $color:此参数用于保留图像的颜色。

返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。

以下示例程序旨在说明PHP中的imagestring()函数。
程序1:

<?php 
   
// Create the size of image or blank image 
$image = imagecreate(500, 300); 
   
// Set the background color of image 
$background_color = imagecolorallocate($image, 0, 153, 0); 
   
// Set the text color of image 
$text_color = imagecolorallocate($image, 255, 255, 255); 
   
// Function to create image which contains string. 
imagestring($image, 5, 180, 100"GeeksforGeeks", $text_color); 
imagestring($image, 3, 160, 120"A computer science portal", $text_color); 
   
header("Content-Type: image/png"); 
   
imagepng($image); 
imagedestroy($image); 
?>

输出:
create image function

程序2:

<?php 
  
// Create the size of image or blank image 
$image = imagecreate(500, 300); 
  
// Set the background color of image 
$background_color = imagecolorallocate($image, 255, 255, 255); 
  
// Set the text color of image 
$text_color = imagecolorallocate($image, 0, 153, 0); 
  
// Function to create image which contains string. 
imagestring($image, 5, 50, 100,  
     "GeeksforGeeks: A computer science portal", $text_color); 
  
header("Content-Type: image/png"); 
  
imagepng($image); 
imagedestroy($image); 
?>

输出:
imagestring function

相关文章:

参考: http://php.net/manual/en/function.imagestring.php



相关用法


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