PHP | imagechar()函数

这个 imagechar() 函数是PHP中的一个内置函数,用于水平绘制字符。此函数用于绘制图像中字符串的第一个字符,该字符由图像及其x轴和y轴标识。左上角的坐标是(0,0)。

null

语法:

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

参数: 此函数接受六个参数,如下所述:

  • $image: 它由一个图像创建函数返回,例如imagecreatetruecolor()。它用于创建图像的大小。
  • $font: 此参数用于设置字符的字体大小。对于拉丁2编码的内置字体,其值可以是1、2、3、4、5。数字越大表示字体越大,数字越小表示字体越小。
  • $x: 此参数用于设置x坐标以打印图像中的字符。
  • $y: 此参数用于设置y坐标以打印图像中的字符。
  • $c: 打印出来的字符。
  • $color: 它设置图像的颜色。由imagecolorallocate()函数创建的颜色标识符。

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

下面的程序说明了 imagechar() PHP中的函数:

项目1:

<?php
// Creates image size
$image = imagecreate(400, 300);
$string = 'GeeksForGeeks' ;
// Set background color
$bg = imagecolorallocate( $image , 0, 153, 0);
// Set text color.
$white = imagecolorallocate( $image , 255, 255, 255);
// Prints a white G character
imagechar( $image , 5, 190, 150, $string , $white );
header( 'Content-type: image/png' );
imagepng( $image );
?>


输出: image

项目2:

<?php
// 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 text color
$white = imagecolorallocate( $image , 255, 255, 255);
for ( $i = 0; $i < $len ; $i ++)
// Prints white character of string using loop
imagechar( $image , 6, 190 + 10 * $i , 150, $string [ $i ], $white );
header( 'Content-type: image/png' );
imagepng( $image );
?>


输出: image

相关文章:

参考: http://php.net/manual/en/function.imagechar.php

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享