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);
?>
输出:
程序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);
?>
输出:
相关文章:
参考: http://php.net/manual/en/function.imagestring.php
相关用法
- PHP cos( )用法及代码示例
- p5.js nfs()用法及代码示例
- p5.js nfp()用法及代码示例
- d3.js d3.hcl()用法及代码示例
- PHP sin( )用法及代码示例
- p5.js nf()用法及代码示例
- p5.js nfc()用法及代码示例
- PHP tan( )用法及代码示例
- PHP pow( )用法及代码示例
- d3.js d3.map.set()用法及代码示例
- CSS var()用法及代码示例
- PHP next()用法及代码示例
注:本文由纯净天空筛选整理自Mahadev99大神的英文原创作品 PHP | imagestring() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。