📜  PHP | imagickdraw clear()函数

📅  最后修改于: 2022-05-13 01:56:38.747000             🧑  作者: Mango

PHP | imagickdraw clear()函数

ImagickDraw::clear()函数是PHP中的一个内置函数,用于清除 ImagickDraw 对象的所有累积命令,并将其包含的设置重置为默认值。

句法:

bool ImagickDraw::clear( void )

参数:此函数不接受任何参数。

返回值:此函数在成功时返回 TRUE。

异常:此函数在出错时抛出 ImagickException。

下面给出的程序说明了PHP中的ImagickDraw::clear()函数
方案一:

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();
?>

输出:

方案二:

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