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, string $tile_geometry, 
                      string $thumbnail_geometry, int $mode, string $frame )

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

  • $draw: It specifies the font name, size, and color.
  • $tile_geometry: It specifies the number of tiles per row and page.
  • $thumbnail_geometry: It specifies the preferred image size and border size of each thumbnail.
  • $mode: It contains an integer value corresponding to one of MONTAGEMODE constants.
  • $frame: It specifies whether surrounds the image with an ornamental border.

List of all MONTAGEMODE constants are given below:

  • imagick::MONTAGEMODE_FRAME (1)
  • imagick::MONTAGEMODE_UNFRAME (2)
  • imagick::MONTAGEMODE_CONCATENATE (3)

Return Value: This function returns a new Imagick object on success.



Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::montageImage() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Imagick object
$imagick = new Imagick(
  
// Create a montage
$result = $imagick->montageImage(new ImagickDraw(), '4x2',
        '150x100+2+2', imagick::MONTAGEMODE_UNFRAME, "2x2+3+3");
  
// Display the image
$result->setImageFormat('png');
header("Content-Type: image/png");
  
echo $result->getImageBlob();
?>

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new Imagick object
$imagick = new Imagick();
  
// Create a new Image with label
$imagick->newimage(1000, 800, 'green');
$imagick->labelImage('green');
  
// Add a new Image with label
$imagick->addImage(new imagick(
  
$imagick->labelImage('Image1');
  
// Add a new Image with label
$imagick->addImage(new imagick(
  
$imagick->labelImage('Image2');
  
// Create a new Image with label
$imagick->newimage(1000, 800, 'blue');
$imagick->labelImage('blue');
  
// Create a new Image with label
$imagick->newimage(1000, 800, 'violet');
$imagick->labelImage('violet');
  
// Create a new Image with label
$imagick->newimage(1000, 800, 'cyan');
$imagick->labelImage('cyan');
  
// Create a montage
$result = $imagick->montageImage(new ImagickDraw(), "3x2+0+0"
     "200x160+3+3>", Imagick::MONTAGEMODE_CONCATENATE, "10x10+2+2");
  
// Display the image
$result->setImageFormat('png');
header("Content-Type: image/png");
  
echo $result->getImageBlob();
?>

chevron_right


Output:

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