PHP | ImagickDraw setFillPatternURL() Function

The ImagickDraw::setFillPatternURL() function is an inbuilt function in PHP which is used to set the URL to use as a fill pattern for filling objects. The URL actually is a unique name of a pattern with a ‘#’ before the name.

Syntax:

bool ImagickDraw::setFillPatternURL( string $fill_url )

Parameters: This function accepts a single parameter $fill_url which holds the URL.

Return Value: This function returns TRUE on success.

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



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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 = ['blue', '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 fill Opacity
$draw->setFillOpacity(0);
  
// Set the fill pattern URL
$draw->setFillPatternURL('#MyPattern');
  
// Draw a rectangle on which pattern is made
$draw->rectangle(0, 0, 400, 400);
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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->rectangle($x, $y + 80, $x % 2, $y);
    }
}
  
// Pop the pattern
$draw->popPattern();
  
// Set the fill Opacity
$draw->setFillOpacity(0);
  
// Set the fill pattern URL
$draw->setFillPatternURL('#MyPattern');
  
// Draw a rectangle on which pattern is made
$draw->rectangle(0, 0, 900, 900);
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagickdraw.setfillpatternurl.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.