I added an image in the panel. Then I try to get it as a thumbnail.
echo $site->theme_favicon()->thumb(['width' => 128])->url();
I’m not sure if it’s a bug but the url I get is
http://mydomain.com/my-image.jpg. It’s not in
thumbs and it’s not suffixed with dimensions.
My image is not saved. Does thumb not work with
I use Kirby 2.5.8
Since when is
thumb() a field method? Have I missed something?
Even if that did work, it wouldn’t be a good idea to call either the thumb or the URL method if you don’t even know if you have an image object :pullinghairout: (missing emoji).
Theoretically, you could do this:
<?= $site->theme_favicon()->toFile()->thumb(['width' => 128])->url(); ?>
But this is not recommended!
Better do it like this (how often do I have to repeat this?):
<?= ($image = $site->theme_favicon()->toFile())? $image->resize(128)->url(): ''; ?>
thumb() instead of resize, if you prefer)
First of all, I misread the docs here: https://getkirby.com/docs/templates/thumbnails.
It looks like a field method, but image in this case is not a field, but a Kirby function.
echo $page->image('cover.jpg')->thumb(array('width' => 300));
In general I think it should be as easy to create a thumb for site as it is for page.
Anyway, I want it to throw an error if the file is missing so I have shorten it a bit:
<?= $site->theme_favicon()->toFile()->resize(128)->url(); ?>
:sonjapullinghairout: (missing emoji)
An image in my case is required. If it’s missing I really want to be aware of that.
There is no difference at all between the site object and the page object as regards creating thumbs!
Well, as long as you have full control over the page and nobody else can delete your images afterwards on the production site etc. etc., I guess it’s ok.