ImagickDraw::clear()函数是PHP中的内置函数,用于清除ImagickDraw对象的所有累积命令,并将其中包含的设置重置为默认值。
用法:
bool ImagickDraw::clear( void )
参数:此函数不接受任何参数。
返回值:成功时此函数返回TRUE。
异常:该函数在错误时引发ImagickException。
下面给出的程序说明了PHP中的ImagickDraw::clear()函数:
示例1:
<?php
//Create a new Imagick object
$imagick = new Imagick();
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the text properties
$draw->setFontSize(110);
$draw->setFillColor('green');
// Apply the annotation() function
$draw->annotation(20, 120, 'Random Content');
// Clear the object which means commands
// written above are all deleted now
$draw->clear();
// Set the font size
$draw->setFontSize(110);
$draw->setFillColor('white');
// Apply the annotation() function
$draw->annotation(20, 120, 'New Content');
// Render the draw commands in the ImagickDraw object
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat("png");
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
示例2:
<?php
//Create a new Imagick object
$imagick = new Imagick();
// Create a image on imagick object
$imagick->newImage(800, 250, 'white');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the text properties
$draw->setFontSize(110);
$draw->setFillColor('green');
// Apply the annotation() function
$draw->annotation(20, 120, 'GeeksforGeeks');
// Clear the object which means commands written
// above are not all deleted now
$draw->clear();
// Render the draw commands in the ImagickDraw object
$imagick->drawImage($draw);
// Show the output
$imagick->setImageFormat("png");
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>
输出:
This will throw ImagickException because $draw is emptied by clear(), thus cannot be drawn.
参考: https://www.php.net/manual/en/imagickdraw.clear.php
相关用法
- PHP ImagickDraw pop()用法及代码示例
- PHP ImagickDraw arc()用法及代码示例
- PHP DS\Map clear()用法及代码示例
- p5.js clear()用法及代码示例
- PHP Ds\Set clear()用法及代码示例
- d3.js d3.map.clear()用法及代码示例
- d3.js d3.set.clear()用法及代码示例
- PHP ImagickDraw popDefs()用法及代码示例
- PHP ImagickDraw popClipPath()用法及代码示例
- PHP ImagickDraw setTextDecoration()用法及代码示例
- PHP ImagickDraw setTextUnderColor()用法及代码示例
- PHP ImagickDraw pushClipPath()用法及代码示例
- PHP ImagickDraw pushDefs()用法及代码示例
- PHP ImagickDraw getTextAntialias()用法及代码示例
- PHP ImagickDraw pathMoveToRelative()用法及代码示例
注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | ImagickDraw clear() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。