如何使用 PHP 中的 imagestringup() 函数垂直绘制字符串?
phpserver side programmingprogramming
imagestringup() 是 PHP 中的内置函数,用于垂直绘制图像。
语法
bool imagestringup ($image, $font, $x, $y, $string, $color)
参数
imagestring() 接受六个参数:$image、$font、$x、$y、$string 和 $color。
$image − $image 参数使用 imagecreatetruecolor() 函数创建给定大小的空白图像。
$font − $font 参数用于为内置字体或使用 imageloadfont() 函数注册的其他字体标识符设置字体大小值,分别为 1、2、3、4 和 5。
$x − 保存字体在水平 X 轴上最左上角的位置。
$y −保存字体在垂直 Y 轴上最上角的位置。
$string − $string 参数保存要写入的字符串。
$color − 此参数保存图像的颜色。
返回值
imagestring() 成功时返回 True,失败时返回 False。
示例
<?php // 使用 imagecreatetruecolor() 函数创建 250*190 图像 $img = imagecreatetruecolor(700, 300); // 设置图像的背景颜色 $bgcolor = imagecolorallocate($img, 122, 122, 122); // 用上面选择的颜色填充背景 imagefill($img, 0, 0, $bgcolor); // 写入白色文本 $textcolor = imagecolorallocate($img, 255, 255, 255); imagestringup($img, 6, 130, 150, 'Hello World', $textcolor); // 将图片输出到浏览器 header('Content-type: image/png'); imagepng($img); ?>