PHP | imagickdraw comment()函数
ImagickDraw::comment()函数是PHP中的一个内置函数,用于向矢量输出流添加注释。注释附加在输出流的末尾。
句法:
bool ImagickDraw::comment( string $comment )
参数:此函数接受一个包含注释的参数$ comment。
返回值:此函数在成功时返回 TRUE。
异常:此函数在出错时抛出 ImagickException。
下面给出的程序说明了PHP中的ImagickDraw::comment()函数:
方案一:
newImage(800, 250, 'white');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Add comment
$draw->comment('Hello ! This is my comment.');
// Get the vector graphics as string
$graphics = $draw->getVectorGraphics();
// Get comment from vector graphics
$comment = substr($graphics, 807);
echo $comment;
?>
输出:
Hello ! This is my comment.
方案二:
newImage(800, 250, 'white');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
$string = 'This is my comment';
// Add comment
$draw->comment($string);
// Get the vector graphics
$graphics = $draw->getVectorGraphics();
// Get comment from vector graphics
$getComment = substr($graphics, 807, strlen($string));
// Set the font size
$draw->setFontSize(50);
// Write on image
$draw->annotation(50, 100, $getComment);
// Render the draw commands
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
参考: https://www. PHP.net/manual/en/imagickdraw.comment。 PHP