How can multiple images be output in a PHP script using imagick?

To output multiple images in a PHP script using Imagick, you can create a loop to iterate through each image file and display or save them individually. This can be achieved by loading each image file, performing any necessary image processing operations, and then outputting or saving the processed image.

<?php
// Array of image file paths
$imageFiles = ['image1.jpg', 'image2.jpg', 'image3.jpg'];

// Loop through each image file
foreach ($imageFiles as $imageFile) {
    // Create Imagick object
    $imagick = new Imagick($imageFile);

    // Perform any necessary image processing operations
    // For example, resizing the image
    $imagick->resizeImage(200, 200, Imagick::FILTER_LANCZOS, 1);

    // Output or save the processed image
    header('Content-Type: image/jpeg');
    echo $imagick->getImageBlob();

    // Or save the processed image to a file
    // $imagick->writeImage('processed_' . $imageFile);

    // Clear Imagick object
    $imagick->clear();
    $imagick->destroy();
}
?>