PHP | Imagick compositeImage() Function
The Imagick::compositeImage() function is an inbuilt function in PHP which is used to composite one image into another image and gives composite image.
Syntax:
bool Imagick::compositeImage( $composite_object, $composite,
$x, $y, $channel = Imagick::CHANNEL_DEFAULT )
Parameters: This function accepts five parameters as mentioned above and described below:
- $composite_object: It is an Imagick object which holds the composite image or may be realpath of image to compose.
- $composite: It is a Composite Operator Constants such as Imagick::COMPOSITE_DEFAULT, Imagick::COMPOSITE_MATHEMATICS, etc…
- x: It holds the column offset of the composited image. The x value will be the numeric format.
- y: It is hold the row offset of the composited image. The y value will be the numeric format.
- $channel: It has Imagick channel constants which provides any channel constant that is valid for your channel mode. To apply more than one channel, combine channel type constants using bitwise operators.
- PHP | Imagick affineTransformImage() Function
- PHP | Imagick implodeImage() Function
- PHP | Imagick liquidRescaleImage() Function
- PHP | Imagick optimizeImageLayers() Function
- PHP | Imagick medianFilterImage() Function
- PHP | Imagick pingImage() Function
- PHP | Imagick getImageResolution() Function
- PHP | Imagick displayImage() Function
- PHP | Imagick getImageDepth() Function
- PHP | Imagick blueShiftImage() Function
- PHP | Imagick transparentPaintImage() Function
- PHP | Imagick getImageLength() Function
- PHP | Imagick setImageResolution() Function
- PHP | Imagick cycleColormapImage( ) Function
- PHP | Imagick getQuantumDepth() Function
Return Value: It returns Boolean value True on success and false on failure.
Below program illustrates the Imagick::compositeImage() function in PHP:
Program:
<?php // Declare Imagick objects $image1 = new \Imagick( $image2 = new \Imagick( // Resize the images $image1->resizeimage($image2->getImageWidth(), $image2->getImageHeight(), \Imagick::FILTER_LANCZOS, 1); // Create new Imagick object $new_image = new \Imagick(); // Create new image using ImageMagick pseudo-formats $new_image->newPseudoImage($image1->getImageHeight(), $image1->getImageWidth(), "gradient:gray(10%)-gray(90%)"); // Rotate the image $new_image->rotateimage('black', 90); // Use composite function to combined the image $image2->compositeImage($new_image, \Imagick::COMPOSITE_COPYOPACITY, 0, 0); // Use composite function to combined the image $image1->compositeImage($image2, \Imagick::COMPOSITE_ATOP, 0, 0); header("Content-Type: image/jpg"); // Display the output echo $image1->getImageBlob(); ?> |
Output:

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



