Hi everyone! I’d like to pick several images from different folders, so I’m using the Controlled List plugin to create checkboxes in the panel. The callable
looks like this:
<?php
class ScreenshotCollection {
static function screenshotlist($field) {
$kirby = kirby();
$site = $kirby->site();
$pages = $site->pages();
$screenshotPage = $pages->find('screenshots');
$games = $screenshotPage->children()->visible();
$screenshots = new Collection();
foreach ($games as $g) {
foreach ($g->images() as $i) {
$screenshots->data[] = $i;
}
}
$screenshots = $screenshots->filterBy('ratio', '>=', '1.5')->sortBy('modified', 'desc')->limit(16);
$result = array();
foreach ($screenshots as $screenshot) {
if($screenshot->title()->isNotEmpty()){
$result[$screenshot->url()] = $screenshot->title() . ' / ' . $screenshot->page()->title();
} else{
$result[$screenshot->url()] = $screenshot->name() . ' / ' . $screenshot->page()->title();
}
}
return $result;
}
}
After that, I’d like to get a random image from this list and create a thumbnail for it . Currently the code looks like this:
<?php $screenshotlist=page('screenshots')->featuredscreenshots()->split();$key=array_rand($screenshotlist);$screenshot=$screenshotlist[$key];?>
Now, for the problem: Since $screenshot
only outputs the URL (as specified in the callable), I can’t seem to use thumb
to create a thumbnail. Is there anything I can do to save the $result
in a way that allows me to do this? Any help would be greatly appreciated!