Open In App

PHP | ImagickDraw pathClose() Function

Last Updated : 17 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The ImagickDraw::pathClose() function is an inbuilt function in PHP which is used to add a path element to the current path which closes the current subpath by drawing a straight line. In simple words, it is used to completely apply a stroke to all the edges.

Syntax:

bool ImagickDraw::pathClose( void )

Parameters: This function doesn’t accepts any parameters.

Return Value: This function returns TRUE on success.

Below programs illustrate the ImagickDraw::pathClose() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the stroke color
$draw->setStrokeColor('white');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Create a shape with four corners using
// paths with pathClose() function
$draw->pathStart();
$draw->pathMoveToAbsolute(420, 50);
$draw->pathMoveToRelative(20, 0);
$draw->pathLineToRelative(50, 90);
$draw->pathLineToVerticalRelative(30);
$draw->pathLineToHorizontalAbsolute(250);
$draw->pathClose();
$draw->pathFinish();
  
// 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();
  
// Add texts to image
$draw->annotation(100, 200, 'With pathClose()');
$draw->annotation(500, 200, 'Without pathClose()');
  
// Set the stroke color
$draw->setStrokeColor('green');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Create a shape with three coreners using
// paths (with pathClose())
$draw->pathStart();
$draw->pathMoveToAbsolute(20, 50);
$draw->pathMoveToRelative(20, 0);
$draw->pathLineToRelative(50, 90);
$draw->pathLineToVerticalRelative(0);
$draw->pathLineToHorizontalAbsolute(250);
$draw->pathClose();
$draw->pathFinish();
  
// Create the same shape using
// paths (without pathClose())
$draw->translate(400, 0);
$draw->pathStart();
$draw->pathMoveToAbsolute(20, 50);
$draw->pathMoveToRelative(20, 0);
$draw->pathLineToRelative(50, 90);
$draw->pathLineToVerticalRelative(0);
$draw->pathLineToHorizontalAbsolute(250);
$draw->pathFinish();
  
// 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.pathclose.php



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads