Use `thumb()`on an image inside a subfolder of the site folder


How would I use thumb() on an image located inside a subfolder of the site folder?

How do I get this to work:

$test = $kirby->roots()->site() . DS . "test" . DS . "test.jpg";
// Output: '/var/www/my-site/site/test/test.jpg'
// Output: true
thumb($test, array("width" => 300));
// Nothing happens

FYI: Using the thumb() file method elsewhere in the site just works. But since this image isn’t located in the content folder I don’t have a file object to work with…


Hm, maybe it works with the Asset class?

Why would you want. to put. a file into the site folder? Ideally, that folder lives outside the web root and is not accessible.


I just tried

$test = $kirby->roots()->site() . DS . "test" . DS . "test.jpg";
thumb($test, array("width" => 300));
$testAsMedia = new Media($test);
thumb($testAsMedia, array("width" => 300));
$testAsAsset = new Asset($test);

But no generating of the thumb.


It’s a cache basically. I consists of images, 1 for each page from an uploaded pdf in the content. As this is an expensive operation, I’ld like to delegate that to a worker. But, I need those images in the front end later, and I’ld like to use the thumb() helper for that.


FYI: It works with the Asset class, but the gotcha was it needs it path to be relative to the kirby installation.
I really should read docs more thoroughly :see_no_evil:

thumb(new Asset("site" . DS . "test" . DS . "test.jpg"), array("width" => 300));
// 🎉 works

Thanks a lot again @texnixe


Was just going to say you need a relative path…