imagestring
(PHP 4, PHP 5, PHP 7)
imagestring - 水平绘制一个字符串
描述
bool imagestring ( resource $image , int $font , int $x , int $y , string $string , int $color )
在给定的坐标处绘制一个字符串。
参数
`image`
一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。
`font`
对于latin2编码(其中较大的数字对应较大的字体)或使用imageloadfont()注册的任何自己的字体标识符,可以为1,2,3,4,5。
x
左上角的x坐标。
y
左上角的y坐标。
string
要写入的字符串。
color
使用imagecolorallocate()创建的颜色标识符。
返回值
成功返回TRUE或失败时返回FALSE。
例子
示例#1 imagestring()示例
<?php
//?Create?a?100*30?image
$im?=?imagecreate(100,?30);
//?White?background?and?blue?text
$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);
?>
上面的例子会输出类似于:
扩展内容
- imageloadfont() - 加载一个新的字体
- imagettftext() - 使用TrueType字体将文本写入图像
← imagesettile
imagestringup →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com