PHP | ImagickDraw pushClipPath() Function
Last Updated :
30 Dec, 2019
The ImagickDraw::pushClipPath() function is an inbuilt function in PHP which is used to starts 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::pushClipPath( string $clip_mask_id )
Parameters: This function accepts a single parameter $clip_mask_id which holds the name of the clip path.
Return Value: This function returns TRUE on success.
Below programs illustrate the ImagickDraw::pushClipPath() function in PHP:
Program 1:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setStrokeColor( 'blue' );
$draw ->setFillColor( 'cyan' );
$draw ->setStrokeWidth(2);
$draw ->pushClipPath( 'testClipPath' );
$draw ->rectangle(0, 0, 300, 300);
$draw ->popClipPath();
$draw ->setClipPath( 'testClipPath' );
$draw ->circle(150, 50, 300, 150);
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Program 2:
<?php
$imagick = new Imagick();
$imagick ->newImage(800, 250, 'white' );
$draw = new ImagickDraw();
$draw ->setFillColor( 'green' );
$draw ->setFontSize(90);
$draw ->pushClipPath( 'testClipPath' );
$draw ->circle(200, 200, 300, 300);
$draw ->popClipPath();
$draw ->setClipPath( 'testClipPath' );
$draw ->annotation(115, 200, 'GeeksforGeeks' );
$imagick ->drawImage( $draw );
$imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagickdraw.pushclippath.php
Share your thoughts in the comments
Please Login to comment...