array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.imagestring.php', 1 => 'imagestring', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD 和图像处理 函数', ), 'prev' => array ( 0 => 'function.imagesettile.php', 1 => 'imagesettile', ), 'next' => array ( 0 => 'function.imagestringup.php', 1 => 'imagestringup', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/image/functions/imagestring.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imagestring — 水平绘制字符串
在指定坐标处水平绘制 string
。
image
由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。
font
取值对于内建的 latin2 编码字体可以是:1、2、3、4、5(更高的数字对应更大的字体), 或是通过 imageloadfont() 返回的 GdFont 实例。
x
左下角的 x 坐标。
y
左下角的 y 坐标。
string
要写入的字符串。
color
颜色标识符使用 imagecolorallocate() 创建。
版本 | 说明 |
---|---|
8.1.0 |
font 参数现在接受 GdFont
实例和 int,之前仅接受 int。
|
8.0.0 |
image 现在需要 GdImage 实例;之前需要有效的 gd resource。
|
示例 #1 imagestring() 示例
<?php
// 创建 100*30 图像
$im = imagecreate(100, 30);
// 白色背景和蓝色文字
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// Write the string at the top left
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);
// Output the image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
以上示例的输出类似于: