Tuesday, September 24, 2024
Google search engine
HomeLanguagesPHP | ImagickDraw setStrokeDashArray() Function

PHP | ImagickDraw setStrokeDashArray() Function

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

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

Recent Comments