PHP | imagickdraw pop()函数
ImagickDraw::pop()函数是PHP中的一个内置函数,用于销毁堆栈中的当前 ImagickDraw,并返回之前推送的 ImagickDraw。对于每个pop()函数,必须已经有一个等效的push()函数。
句法:
bool ImagickDraw::pop( void )
参数:此函数不接受任何参数。
返回值:此函数在成功时返回 TRUE。
下面的程序说明了PHP中的ImagickDraw::pop()函数:
方案一:
newImage(800, 250, 'white');
// Create a new ImagickDraw object
$draw = new ImagickDraw();
// Set the fill color
$draw->setFillColor('blue');
// Set the font size
$draw->setFontSize(70);
// Push
$draw->push();
// Annotate a text
$draw->annotation(250, 70, 'Hello');
// Pop
$draw->pop();
// Set the fill color for new object
$draw->setFillColor('green');
// Annotate a text
$draw->annotation(250, 170, 'World');
// Render the draw commands
$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 stroke color
$draw->setStrokeColor('red');
// Set the fill color
$draw->setFillColor('blue');
// Set the stroke width
$draw->setStrokeWidth(5);
// Set the font size
$draw->setFontSize(72);
// Push
$draw->push();
// Translate the object
$draw->translate(50, 50);
// Draw a circle
$draw->circle(250, 70, 250, 130);
// Pop because we want to draw a new
// circle with new properties.
$draw->pop();
// Set the stroke color for new object
$draw->setStrokeColor('violet');
// Set the fill color for new object
$draw->setFillColor('green');
// Draw a new circle
$draw->circle(250, 70, 250, 130);
// 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.pop。 PHP