首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

imagestring

(PHP 4, PHP 5, PHP 7)

imagestring - 水平绘制一个字符串

描述

代码语言:javascript
复制
bool imagestring ( resource $image , int $font , int $x , int $y , string $string , int $color )

在给定的坐标处绘制一个字符串。

参数

代码语言:txt
复制
`image`   

一个图像资源,由图像创建函数之一返回,如imagecreatetruecolor()。

代码语言:txt
复制
`font`   

对于latin2编码(其中较大的数字对应较大的字体)或使用imageloadfont()注册的任何自己的字体标识符,可以为1,2,3,4,5。

x

左上角的x坐标。

y

左上角的y坐标。

string

要写入的字符串。

color

使用imagecolorallocate()创建的颜色标识符。

返回值

成功返回TRUE或失败时返回FALSE。

例子

示例#1 imagestring()示例

代码语言:javascript
复制
<?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 →

扫码关注腾讯云开发者

领取腾讯云代金券