php char(),PHP imagecharup()用法及代码示例

imagecharup()函数是PHP中的内置函数,用于垂直绘制字符。此功能在图像标识的图像的x和y轴上绘制字符串的第一个字符。左上角的坐标为(0,0)。

用法:

bool imagecharup( $image, $font, $x, $y, $c, $color )

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

$image:它由图像创建功能之一(例如imagecreatetruecolor())返回。它用于创建图像的尺寸。

$font:此参数用于设置字符的字体大小。对于采用latin2编码的内置字体,其值可以为1、2、3、4、5。较高的数字表示较大的字体,较小的数字表示较小的字体。

$x:此参数用于设置x坐标以在图像中打印字符。

$y:此参数用于设置y坐标以在图像中打印字符。

$c:打印的字符。

$color:它设置颜色。由imagecolorallocate()函数创建的颜色标识符。

返回值:成功时此函数返回true,失败时返回false。

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

程序1:

// Creates the image size

$image = imagecreate(400, 300);

$string = 'GeeksForGeeks';

// Set background color

$bg = imagecolorallocate($image, 0, 153, 0);

// Set character color

$white = imagecolorallocate($image, 255, 255, 255);

// prints a white G character

imagecharup($image, 5, 190, 150, $string, $white);

header('Content-type: image/png');

imagepng($image);

?>

输出:

33be244a9bc4a83f10a347cdd5f5e865.png

程序2:

// Create image size

$image = imagecreate(400, 300);

$string = 'GeeksforGeeks';

// Find string length

$len = strlen($string);

// Set background color

$bg = imagecolorallocate($image, 0, 153, 0);

// Set character color

$white = imagecolorallocate($image, 255, 255, 255);

// Use loop to print string

for($i = 0; $i < $len; $i++)

// Prints a white character $len times

imagecharup($image, 6, 190, 230 - 10 * $i, $string[$i], $white);

header('Content-type: image/png');

imagepng($image);

?>

输出:

d5bdd908f77561fad6b5101296c8978a.png

相关文章:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值