Open In App

PHP | Gmagick compositeimage() Function

Last Updated : 14 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.




<?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;  
?>


Output:

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




<?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;  
?>  


Output:

Reference: https://www.php.net/manual/en/gmagick.compositeimage.php



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads