PHP Imagick function mergeImageLayers ()

PHP

Syntax:
Imagick Imagick::mergeImageLayers (int $layer_method)
Parameters:This function takes one parameter, $layer_method,which contains an integer value corresponding to one of LAYERMETHOD constants . You can also pass constants directly like mergeImageLayers (Imagick::LAYERMETHOD_COMPAREANY).The list of LAYERMETHOD constants is 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 object Imagick containing the new image.Exceptions:This function throws an ImagickException on error.The following programs illustrate the Imagick::mergeImageLayers() function in PHP:Program 1:  
// Create a new Imagick object $imagick = new Imagick ( ' https://media.engineerforengineer.org/wp-content/uploads/20190918234528/colorize1.png ' );  
// Add another image to the same object $imagick -> addImage ( new Imagick ( ' https://media.engineerforengineer.org/wp-content/uploads/20191126190119/engineerforengineer-copy.png ' ));  
// Set opacity $imagick -> setImageOpacity (0.5);  
// Merge layers $result = $imagick -> mergeImageLayers (Imagick::LAYERMETHOD_FLATTEN);  
// Show image header ( "Content-Type: image / png" ); echo $result -> getImageBlob(); ?>
Output: Program 2:  
// Create new Imagick object $imagick = new Imagick ( ' https://media.engineerforengineer.org/wp-content/uploads/20190918234528/colorize1.png ' );  
// Add another image to the same object $imagick -> addImage ( new Imagick ( ' https://media.engineerforengineer.org/wp-content/uploads/20191126191401/engineerforengineerhalf.png ' ));  
// Set opacity $imagick -> setImageOpacity (0.7);  
// Merge layers $result = $imagick -> mergeImageLayers (11);  
// Show image header ( "Content-Type: image / png" ); echo $result -> getImageBlob(); ?>
Output: Link: https://www.php.net/manual/en/imagick.mergeimagelayers.php



Get Solution for free from DataCamp guru