Thursday, December 18, 2025
HomeLanguagesPHP | ImagickDraw pushClipPath() Function

PHP | ImagickDraw pushClipPath() Function

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
  
// 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');
   
// Create a rectangle which is
// the area to be clipped
$draw->rectangle(0, 0, 300, 300);
   
// Pop the clip path
$draw->popClipPath();
   
// Set the clip path
$draw->setClipPath('testClipPath');
   
$draw->circle(150, 50, 300, 150);
   
// 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 the fill color
$draw->setFillColor('green');
  
// Set the font size
$draw->setFontSize(90);
   
// Push the clip path
$draw->pushClipPath('testClipPath');
   
// Create a circle which is
// the area to be clipped
$draw->circle(200, 200, 300, 300);
   
// Pop the clip path
$draw->popClipPath();
   
// Set the clip path
$draw->setClipPath('testClipPath');
   
// Annotate a text
$draw->annotation(115, 200, 'neveropen');
   
// 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.pushclippath.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12035 POSTS0 COMMENTS
Shaida Kate Naidoo
6957 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS