PHP | ImagickDraw composite() Function

The ImagickDraw::compose() function is an inbuilt function in PHP which is used to composite an image into the current image, using the specified composition operator, specified position, and at the specified size.

Syntax:

bool ImagickDraw::compose( int $compose, float $x, float $y,
           float $width, float $height, Imagick $compositeWand )

Parameters: This function accepts six parameters as mentioned above and described below:

  • $compose: It specifies the composition operator which corresponds on of COMPOSITE constants.
  • $x: It specifies y-coordinate of the top left corner.
  • $y: It specifies x-coordinate of the top left corner.
  • $width: It specifies width of the composition image.
  • $height: It specifies height of the composition image.
  • $compositeWand: It specifies the Imagick object where composition image is taken from.

Return Value: This function returns TRUE on success.

Below programs illustrate the ImagickDraw::compose() 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 new ImagickDraw object
$draw = new ImagickDraw();
  
// Composite the Image
$draw->composite(imagick::COMPOSITE_COLORIZE,
                   100, 100, 200, 200, $imagick);
  
// Create a new Imagick object
$imagick2 = new Imagick();
  
// Create a image on imagick object
$imagick2->newImage(800, 250, 'white');
  
// Render the draw commands
$imagick2->drawImage($draw);
  
// Add border
$imagick->borderImage('green', 1, 1);
  
// Show the output
$imagick2->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick2->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 new ImagickDraw object
$draw = new ImagickDraw();
  
// Composite the Image
$draw->composite(4, 200, 20, 400, 200, $imagick);
  
// Create a new Imagick object
$imagick2 = new Imagick();
  
// Create a image on imagick object
$imagick2->newImage(800, 250, 'orange');
  
// Render the draw commands
$imagick2->drawImage($draw);
  
// Show the output
$imagick2->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick2->getImageBlob();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/imagickdraw.composite.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.