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);
?>
输出:
程序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);
?>
输出:
相关文章: