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:
<?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();
?> |
Output:
Program 2:
<?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();
?> |
Output:
Reference: https://www.php.net/manual/en/imagickdraw.setfillpatternurl.php