File object from file in assets?

I have a SVG icon file in my assets folder, is it possible to turn it into a file object so that i can easily grab its height() and width() etc?

The easiest way would of cause be to use $site->files and hide those files through the blueprint, but I’m not really sure if I want to lock down file acces through the panel to kirby’s only centralized file storage already :blush:

Yes, you can create a new media object:

<?php
  $image = new Media ('assets/images/logo.svg', url() . '/assets/images/logo.svg');
  //or maybe better
  $image = new Media ($kirby->roots()->assets() . '/images/logo.svg',  $kirby->urls()->assets() . '/images/logo.svg');

  echo $image->size();
 ?>
3 Likes

That works beautifully! :blush: