Composites a set of images while respecting any page offsets and disposal methods. GIF, MIFF, and MNG animation sequences typically start with an image background and each subsequent image varies in size and offset. Returns a new Imagick object where each image in the sequence is the same size as the first and composited with the next image in the sequence.
function coalesceImages()
    $image_paths = [

    $canvas = new Imagick();
    foreach ($image_paths as $image_path) {
    $finalImage = $canvas->coalesceImages();
    $finalImage->setImageIterations(0); //loop forever

    header("Content-Type: image/gif");
    echo $finalImage->getImagesBlob();