$page->image($filename = false)

Returns a specific image $file object by filename. If no filename is given, the first available image will be returned.

  • $filename (string)
    Optional, a filename
  • return ($file)

Example

Fetching the first image

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

Fetching a specific image

<?php if($image = $page->image('myimage.jpg')): ?>
<img src="<?= $image->url() ?>" alt="">
<?php endif ?>

What is an image file?

Kirby considers the following file types as images:

  • jpeg
  • jpg
  • jpe
  • gif
  • png
  • svg
  • ico
  • tif
  • tiff
  • bmp
  • psd
  • ai
  • eps
  • ps