PHP 中的 imagechar() 函数


imagechar() 函数水平绘制一个字符。

语法

bool imagechar( img, font, x, y, ch, color )

参数

  • img:使用 imagecreatetruecolor() 创建的图像。

  • font:设置字体大小

  • x:x 坐标

  • y:y 坐标

  • c:要绘制的字符。

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

返回

imagechar() 函数在成功时返回 TRUE,在失败时返回 FALSE。

示例

以下是示例

<?php
   $img = imagecreate(400, 300);
   $str = 'Demo';
   $bgcolor = imagecolorallocate($img, 30, 80, 70);
   $textcolor = imagecolorallocate($img, 255, 255, 255);
   imagechar($img, 80, 100, 90, $str, $textcolor);
   header('Content-type: image/png');
   imagepng($img);
?>

输出

以下是输出

示例

我们再来看另一个示例,其中我们绘制了一个字符,该字符具有不同的坐标和高宽,如上例所示

<?php
   $img = imagecreate(350, 270);
   $str = 'Example';
   $bgcolor = imagecolorallocate($img, 70, 100, 130);
   $textcolor = imagecolorallocate($img, 200, 195, 210);
   imagechar($img, 100, 50, 70, $str, $textcolor);
   header('Content-type: image/png');
   imagepng($img);
?>

输出

以下是输出

更新于: 31-Dec-2019

100 浏览量

开启你的 职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.