Friday, October 24, 2025
HomeLanguagesPHP | Imagick coalesceImages() Function

PHP | Imagick coalesceImages() Function

The Imagick::coalscaleImages() function is an inbuilt function in PHP which is used to combined the set of images into single image. It composites a set of images with respect to any page offsets and disposal methods. The animation sequences GIF, MIFF, and MNG are typically start with an image background and each subsequent image varies in size and offset.

Syntax:

Imagick Imagick::coalesceImages( void )

Parameters: This function does not accepts any parameters.

Return Value: It returns an Imagick object on success.

Below program illustrates the Imagick::coalscaleImages() function in PHP:

Program: This program generates an animated gif image from a set of images.




<?php
  
$images = [
];
  
// Loading up images in an array 
$temp = new Imagick();
  
foreach ($images as $image) {
    $temp->readImage($image);
    $temp->setImageDelay(100);
}
  
// Reading each image with a delay
// of 100 millisecond time
$temp->setImageFormat('gif');
$gif = $temp->coalesceImages();
  
// Composing set of all images
$gif->setImageFormat('gif');
  
// Setting up output format to gif
$gif->setImageIterations(0);
  
// Infinite iterations of gif
header("Content-Type: image/gif");
  
// Display the image
echo $gif->getImagesBlob();
  
?>


Output:
image file

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

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS