The ImagickDraw::setStrokePatternURL() function is an inbuilt function in PHP which is used to set the pattern used for stroking object outlines.
Syntax:
bool ImagickDraw::setStrokePatternURL( string $stroke_url )
Parameters:This function accepts a single parameter $stroke_url which holds the URL of stroke pattern.
Return Value: This function returns TRUE on success.
Below given programs illustrate the ImagickDraw::setStrokePatternURL() function in PHP:
Program 1: In this program we will create a rectangle with designed outline.
<?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();
// Push the pattern $draw ->pushPattern( "MyPattern" , 0, 0, 50, 50);
$color = [ 'red' , 'black' , 'cyan' ];
for ( $x = 0; $x < 50; $x += 10) {
for ( $y = 0; $y < 50; $y += 5) {
$draw ->setFillColor( $color [ $y % 3]);
$draw ->circle( $x , $y + 80, $x % 2, $y );
}
} // Pop the pattern $draw ->popPattern();
// Set the stroke pattern URL $draw ->setStrokePatternURL( '#MyPattern' );
// Set the stroke width $draw ->setStrokeWidth(10);
// Draw a rectangle on which pattern is made $draw ->rectangle(200, 50, 500, 200);
// Render the draw commands $imagick ->drawImage( $draw );
// Show the output $imagick ->setImageFormat( 'png' );
header( "Content-Type: image/png" );
echo $imagick ->getImageBlob();
?> |
Output:
Program 2: In this program we will create a circle with designed outline.
<?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();
// Push the pattern $draw ->pushPattern( "MyPattern" , 0, 0, 50, 50);
for ( $x = 0; $x < 50; $x += 10) {
for ( $y = 0; $y < 50; $y += 5) {
$draw ->setFillColor( 'green' );
$draw ->rectangle( $x , $y + 10, $x % 5, $y );
}
} // Pop the pattern $draw ->popPattern();
// Set the stroke pattern URL $draw ->setStrokePatternURL( '#MyPattern' );
// Set the stroke width $draw ->setStrokeWidth(10);
// Draw a circle $draw ->circle(300, 100, 350, 20);
// 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.setstrokepatternurl.php