PHP | Gmagick compositeimage() Function

The Gmagick::compositeimage() function is an inbuilt function in PHP which is used to composite one image onto another at the specified offset. Offset is actually the distance from where to start compositing the second image.

Syntax:

Gmagick Gmagick::compositeimage( Gmagick $source, int $COMPOSE, int $x, int $y )

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



  • $source: It specifies the source of image to composite with another image.
  • $compose: It specifies the type of composition to apply.
  • $x: It specifies the x-coordinate.
  • $y: It specifies the y-coordinate.

Return Value: This function returns a Gmagick object containing the composite image.

Exceptions: This function throws GmagickException on error.

Below programs illustrate the Gmagick::compositeimage() function in PHP:

Program 1: This program uses Gmagick::compositeimage() function to composite two images with no offset.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create two new Gmagick object
$gmagick1 = new Gmagick(
  
$gmagick2 = new Gmagick(
  
// Composite the images with no offset
$gmagick1->compositeimage($gmagick2,
          Gmagick::COMPOSITE_MULTIPLY, 0, 0);
  
// Output the image  
header('Content-type: image/png');  
echo $gmagick1;  
?>

chevron_right


Output:

Program 2: This program uses Gmagick::compositeimage() function to composite two image with offset.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create two new Gmagick object
$gmagick1 = new Gmagick(
  
$gmagick2 = new Gmagick(
  
// Composite the images with offset
$gmagick1->compositeimage($gmagick2,
         Gmagick::COMPOSITE_OVER, 300, 0);
  
// Output the image  
header('Content-type: image/png');  
echo $gmagick1;  
?>  

chevron_right


Output:

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