Open In App

PHP | ImagickDraw setStrokeDashArray() Function

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

The ImagickDraw::setStrokeDashArray() function is an inbuilt function in PHP which is used to set the pattern of dashes and gaps used to stroke paths. In case of odd number of values, the list of values is repeated to yield an even number of values. To remove an existing dash array, pass a zero number_elements argument or null dash_array.

Syntax:

bool ImagickDraw::setStrokeDashArray( array $dashArray )

Parameters: This function accepts a single parameter $dashArray which holds the stroke dash.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

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

Program 1:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the stroke dash array
$draw->setStrokeDashArray([80, 5, 2, 5, 15, 51, ]);
  
// Get the stroke dash array
$array = $draw->getStrokeDashArray();
print("<pre>".print_r($array, true)."</pre>");
?>


Output:

Array
(
    [0] => 80
    [1] => 5
    [2] => 2
    [3] => 5
    [4] => 15
    [5] => 51
)

Program 2:




<?php
   
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// 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 fill color
$draw->setFillColor('black');
  
// Set the color of stroke
$draw->setStrokeColor('cyan');
  
// Set the stroke dash array
$draw->setStrokeDashArray([2, 1, 3]);
  
// Draw a ellipse
$draw->ellipse(400, 100, 150, 70, 60, 900);
  
// 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.setstrokedasharray.php



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

Similar Reads