Wednesday, November 20, 2024
Google search engine
HomeLanguagesPHP | Imagick montageImage() Function

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:




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


Output:

Program 2:




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


Output:

Reference: https://www.php.net/manual/en/imagick.montageimage.php

RELATED ARTICLES

Most Popular

Recent Comments