The Imagick::setImageClipMask() function is an inbuilt function in PHP which is used to set the image clip mask.
Syntax:
bool Imagick::setImageClipMask( Imagick $clip_mask )
Parameters: This function accepts $clip_mask as parameter which holds the image clip mask.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the Imagick::setImageClipMask() function in PHP:
Program 1:
<?php   // Create two new imagick objects $imagick = new Imagick(   $clipMask = new Imagick();   $clipMask->setGravity(4);   // Add text to the object $clipMask->newPseudoImage($imagick->getImageWidth(),              $imagick->getImageHeight(), "caption:ClipMaskText");   // Set the clip mask $imagick->setImageClipMask($clipMask); $imagick->negateImage(false);   // Show the output $imagick->setformat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> |
Output:
Program 2:
<?php   // Create two new imagick objects $imagick = new Imagick(   $clipMask = new Imagick();   // Create a rectangular mask $clipMask->newPseudoImage($imagick->getImageWidth(),             $imagick->getImageHeight(), "canvas:Transparent");   $drawMask = new ImagickDraw(); $drawMask->setFillColor('white'); $drawMask->rectangle(170, 0, 470, 300); $clipMask->drawImage($drawMask);   // Set the clip mask $imagick->setImageClipMask($clipMask); $imagick->negateImage(false);   // Show the output $imagick->setformat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> |
Output:
Reference: https://www.php.net/manual/en/imagick.setimageclipmask.php

