Set the iterator to the position in the image list specified with the index parameter. Available since 6.2.9
Selecting layers from source PSD:
Set the iterator to the position in the image list specified with the index parameter. Available since 6.2.9
Parameters
indexintThe position to set the iterator to
function setIteratorIndex($firstLayer)
{
    $imagick = new \Imagick(realpath("images/LayerTest.psd"));
    $output = new \Imagick();
    $imagick->setIteratorIndex($firstLayer);

    do {
        $output->addImage($imagick->getimage());
    } while ($imagick->nextImage());

    $merged = $output->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE);

    $merged->setImageFormat('png');
    header("Content-Type: image/png");
    echo $merged->getImageBlob();
}