Open In App

PHP | ImagickDraw popClipPath() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The ImagickDraw::popClipPath() function is an inbuilt function in PHP which is used to terminate a clip-path definition. Clip paths are used to creates a clipping region that decides which part of an image should be shown. Parts that are inside the region are shown, while those outside are hidden.

Syntax:

bool ImagickDraw::popClipPath( void )

Parameters: This function doesn’t accepts any parameter.

Return Value: This function returns TRUE on success.

Below programs illustrate the ImagickDraw::popClipPath() function in PHP:

Program 1:




<?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 stroke color
$draw->setStrokeColor('blue');
  
// Set the fill color
$draw->setFillColor('cyan');
  
// Set the stroke width
$draw->setStrokeWidth(2);
  
// Push the clip path
$draw->pushClipPath('testClipPath');
  
// This is the area which is going to be visible
$draw->rectangle(0, 0, 250, 250);
  
// Pop the clip path
$draw->popClipPath();
  
// Set the clip path
$draw->setClipPath('testClipPath');
  
// Draw a rectangle
$draw->rectangle(50, 50, 350, 350);
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

Program 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 font size
$draw->setFontSize(60);
  
// Push the clip path
$draw->pushClipPath('testClipPath');
  
// This is the area which is going to be visible
$draw->rectangle(0, 0, 250, 250);
  
// Pop the clip path
$draw->popClipPath();
  
// Set the clip path
$draw->setClipPath('testClipPath');
  
// Annotate the text which is going to be clipped
$draw->annotation(0, 150, 'Hello World');
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagickdraw.popclippath.php



Last Updated : 30 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads