当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP ImagickDraw clear()用法及代码示例


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



相关用法


注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | ImagickDraw clear() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。