Get the first image of $block->images()

I am trying to get the first and then the second image of my block but the following code doesn’t work:

  <?php foreach ($block->images()->toFiles() as $image): ?>
      <?= $image->nth(1) ?>
      <div class="image-number">
        <?php if ($block->imageTag()->isNotEmpty()): ?>
          <p>
              Abb. <?php echo $imageCounter?>
          </p>
        <?php endif ?>
      </div>

      <?= $image->nth(2) ?>
      <div class="image-number">
        <?php $imageCounter++; if ($block->imageTagTwo()->isNotEmpty()): ?>
          <p>
              Abb. <?php echo $imageCounter?>
          </p>
        <?php endif ?>
      </div>
  <?php endforeach ?>

I also tried:

<?= $block->images()->nth(1) ?>

Whats wrong about it?

You can probably use this is() method. Something like …

<?php foreach ($block->images()->toFiles() as $image): ?>

  <?php if($image->is($block->images()->toFiles()->first())): ?>
  <!-- first image stuff -->
  <?php else: ?>
  <!-- other images -->
  <?php endif ?>

  <?php endforeach ?>

This doesn’t work because you are calling nth() which is a collection method on a file object.

Thanks!