Open In App

PHP | ImagickDraw popPattern() Function

Last Updated : 30 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The ImagickDraw::popPattern() function is an inbuilt function in PHP which is used to terminate a pattern definition which contains a design to be applied. Syntax:
bool ImagickDraw::popPattern( void )
Parameters:This function doesn’t accepts any parameter. Return Value: This function returns TRUE on success. Exceptions: This function throws ImagickException on error. Below given programs illustrate the ImagickDraw::popPattern() function in PHP: Program 1: php
<?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) {
        $X = $x + (($y / 10) % 10);
        $draw->rectangle($X, $y, $X + 5, $y + 5);
    }
}

// Pop the pattern
$draw->popPattern();

// Set the fill Opacity
$draw->setFillOpacity(0);

// Set the fill pattern URL
$draw->setFillPatternURL('#MyPattern');

// Draw a rectangle
$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: Program 2: php
<?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) {
        $X = $x + (($y / 10) % 10);
        $draw->circle($X, $y, $X, $y +1);
    }
}

// Pop the pattern
$draw->popPattern();
// Set the fill Opacity
$draw->setFillOpacity(0);

// Set the fill pattern URL
$draw->setFillPatternURL('#MyPattern');

// Draw a rectangle
$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.poppattern.php

Next Article

Similar Reads