Friday, October 17, 2025
HomeLanguagesPHP | ImagickDraw getStrokeDashArray() Function

PHP | ImagickDraw getStrokeDashArray() Function

The ImagickDraw::getStrokeDashArray() function is an inbuilt function in PHP which is used to get an array representing the pattern of dashes and gaps used to stroke paths.

Syntax:

array ImagickDraw::getStrokeDashArray( void )

Parameters: This function doesn’t accepts any parameters.

Return Value: This function returns an array containing stroke dash on success and empty array if it is not set.

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

Program 1:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Get the stroke dash array
$array = $draw->getStrokeDashArray();
print("<pre>".print_r($array, true)."</pre>");
?>


Output:

Array // Empty array which is the default value
(
)

Program 2:




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


Output:

Array
(
    [0] => 20
    [1] => 5
    [2] => 20
    [3] => 5
    [4] => 5
    [5] => 5
)

Program 3:




<?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('red');
  
// Set the font size
$draw->setFontSize(15);
  
// Draw a rectangle
$draw->rectangle(100, 50, 225, 175);
  
// Annotate a text
$draw->annotation(50, 200, 'The strokeDashArray here is default');
  
// Set the stroke dash array
$draw->setStrokeDashArray([20, 5, 19, 15, 5, 15, ]);
  
// Draw a rectangle
$draw->rectangle(500, 50, 625, 175);
  
// Get the stroke dash array
$strokeDashArray = $draw->getStrokeDashArray();
  
// Annotate a text
$draw->annotation(450, 200, 'The strokeDashArray here is ' 
                  . implode(" ", $strokeDashArray));
  
// 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.getstrokedasharray.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS