Loading image for a field

How can I fetch a image from a specific field?

My field is called bild:

bild:
  label: Bild
  type: files
  empty: No images selected yet!
  max: 1
  layout: cards

This just gives me the first image of the page, but not the image I want:

<?php if($image = $page->image()): ?>
  <img srcset="<?= $image->url() ?>" />
<?php endif ?>

Inserting the bild here gives me errors:

<?php if($image = $bild->image()): ?>

I was building onepagers before with Kirby but didn’t have this problem somehow. Seems very basic, so I guess, I don’t understand some important basics here.

Can anyone help?

$bild is not the field. try $page->bild()->toFile() instead.
or use the $page->image('withfilename.jpg’) if you know the filename.

The complete code should be

<?php if($image = $page->bild()->toFile()): ?>
  <img src="<?= $image->url() ?>" />
<?php endif ?>

Thats what I was looking for! Thanks!