Tuesday, November 19, 2024
Google search engine
HomeLanguagesPHP | ImagickDraw setClipPath() Function

PHP | ImagickDraw setClipPath() Function

The ImagickDraw::setClipPath() function is an inbuilt function in PHP which is used to associate a named clipping path with the image. Only the areas drawn on by the clipping path will be modified as long as it remains in effect.

Syntax:

bool ImagickDraw::setClipPath( string $clip_mask )

Parameters: This function accepts a single parameter $clip_mask which holds the clip mask.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickDraw::setClipPath() function in PHP:

Program 1:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
   
// Set the clipPath
$draw->setClipPath('nameOfClipPath');
   
// Get clip path
echo $draw->getClipPath();
?>


Output:

nameOfClipPath

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'green');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Setup a clipPath
$draw->pushClipPath('myClipPath');
$draw->rectangle(100, 40, 200, 200);
$draw->popClipPath();
$draw->setClipPath('myClipPath');
  
// Extra commands which are going to 
// be ignore as they are outside the
// area of the clipPath
$draw->rectangle(10, 100, 400, 400);
$draw->line(100, 100, 400, 400);
  
// 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.setclippath.php

RELATED ARTICLES

Most Popular

Recent Comments