Friday, November 21, 2025
HomeLanguagesPHP | Imagick getImageClipMask() Function

PHP | Imagick getImageClipMask() Function

The Imagick::getImageClipMask() function is an inbuilt function in PHP which is used to get the image clip mask.

Syntax:

array Imagick::getImageClipMask( void )

Parameters: This function does not accept any parameters.

Exceptions: This function throws ImagickException on error.

Return Value: This function returns an Imagick object containing the clip mask.

Below programs illustrate the Imagick::getImageClipMask() function in PHP:

Program 1:




<?php
  
// Create two new imagick objects
$imagick = new Imagick(
$clipMask = new Imagick();
  
$clipMask->newPseudoImage($imagick->getImageWidth(),
                $imagick->getImageHeight(), "caption:ClipMaskText");
  
// Set the clip mask
$imagick->setImageClipMask($clipMask);
  
// Get the clip mask
$getclipMask = $imagick->getImageClipMask();
  
// Show the output
$getclipMask->setformat('png');
header("Content-Type: image/png");
echo $getclipMask->getImageBlob();
?>


Output:

Program 2:




<?php
// Create two new imagick objects
$imagick = new Imagick(
  
$clipMask = new Imagick();
  
$clipMask->setGravity(4);
  
// Add text to the clipMask
$clipMask->newPseudoImage($imagick->getImageWidth(),
                 $imagick->getImageHeight(), "caption:ClipMaskText");
  
$clipMask->setImageBackgroundColor('green');
$clipMask->setImageAlphaChannel(9);
  
// Set the clip mask
$imagick->setImageClipMask($clipMask);
  
// Get the clip mask
$getclipMask = $imagick->getImageClipMask();
  
// Show the output
$getclipMask->setformat('png');
header("Content-Type: image/png");
echo $getclipMask->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagick.getimageclipmask.php

RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6782 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11997 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS