PHP | Imagick mergeImageLayers() Function Last Updated : 04 Dec, 2019 Comments Improve Suggest changes Like Article Like Report The Imagick::mergeImageLayers() function is an inbuilt function in PHP which is used to merge image layers into one. Syntax: Imagick Imagick::mergeImageLayers( int $layer_method ) Parameters: This function accepts a single parameter $layer_method which holds an integer value corresponding to one of LAYERMETHOD constants. You can also pass the constants directly like mergeImageLayers(Imagick::LAYERMETHOD_COMPAREANY). List of LAYERMETHOD constants are given below: imagick::LAYERMETHOD_UNDEFINED (0) imagick::LAYERMETHOD_COALESCE (1) imagick::LAYERMETHOD_COMPAREANY (2) imagick::LAYERMETHOD_COMPARECLEAR (3) imagick::LAYERMETHOD_COMPAREOVERLAY (4) imagick::LAYERMETHOD_DISPOSE (5) imagick::LAYERMETHOD_OPTIMIZE (6) imagick::LAYERMETHOD_OPTIMIZEPLUS (7) imagick::LAYERMETHOD_OPTIMIZEIMAGE (8) imagick::LAYERMETHOD_OPTIMIZETRANS (9) imagick::LAYERMETHOD_REMOVEDUPS (10) imagick::LAYERMETHOD_REMOVEZERO (11) imagick::LAYERMETHOD_COMPOSITE (12) imagick::LAYERMETHOD_MERGE (13) imagick::LAYERMETHOD_FLATTEN (14) imagick::LAYERMETHOD_MOSAIC (15) Return Value: This function returns an Imagick object containing the new image. Exceptions: This function throws ImagickException on error. Below programs illustrate the Imagick::mergeImageLayers() function in PHP: Program 1: php <?php // Create a new Imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/20190918234528/colorize1.png'); // Add another image in the same object $imagick->addImage(new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/20191126190119/geeksforgeeks-copy.png')); // Set the Opacity $imagick->setImageOpacity(0.5); // Merge the Layers $result = $imagick->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN); // Display the image header("Content-Type: image/png"); echo $result->getImageBlob(); ?> Output: Program 2: php <?php // Create a new Imagick object $imagick = new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/20190918234528/colorize1.png'); // Add another image in the same object $imagick->addImage(new Imagick( 'https://media.geeksforgeeks.org/wp-content/uploads/20191126191401/geeksforgeekshalf.png')); // Set the Opacity $imagick->setImageOpacity(0.7); // Merge the Layers $result = $imagick->mergeImageLayers(11); // Display the image header("Content-Type: image/png"); echo $result->getImageBlob(); ?> Output: Reference: https://www.php.net/manual/en/imagick.mergeimagelayers.php Comment More infoAdvertise with us Next Article PHP | Imagick mergeImageLayers() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads PHP | Imagick optimizeImageLayers() Function The Imagick::optimizeImageLayers() function is an inbuilt function in PHP which is used to remove the repeated portions of images to optimize. This function compares each image the GIF disposed forms of the previous image in the sequence. Syntax: bool Imagick::optimizeImageLayers( void) Parameters: 1 min read PHP Imagick morphImages() Function The Imagick::morphImages function is an inbuilt function in PHP that is used to morph a set of images. The image pixels and size of the image are linearly interpolated to give the appearance of metamorphosis from one image to the next. Syntax: Imagick Imagick::morphImages( $number_frames )Parameters 1 min read PHP | Imagick montageImage() Function The Imagick::montageImage() function is an inbuilt function in PHP which is used to create a composite image by combining the many separated images. This function composite the images into the tiles form with the name of image optionally. Syntax: Imagick Imagick::montageImage( ImagickDraw $draw, str 2 min read PHP | Imagick mapImage() Function The Imagick::mapImage() function is an inbuilt function in PHP which is used to replace the colors of an image with the closest color from a reference image. Syntax: bool Imagick::mapImage( Imagick $map, float $dither ) Parameters: This function accepts two parameters as mentioned above and describe 1 min read PHP | Imagick newImage() Function The Imagick::newImage() function is an inbuilt function in PHP which is used to creates a new image. This function creates a new image and associates ImagickPixel value as the background color. Syntax: bool Imagick::newImage( $cols, $rows, $background, $format ) Parameters: This function accepts fo 1 min read Like