Hello,
The thumbnail file is created in “file upload
” hook as below.
kirby()->hook(['panel.file.upload', 'panel.file.replace'], function($file) {
$IDsToProceed = ["home", "test"];
if (in_array($file->page()->id(), $IDsToProceed)) {
thumb($file, array('width' => 300));
}
});
Then I want to reach the thumbnail file in front-end that created via the hook.
I tried $file->thumb()->toArray()
but It creates thumbnail if it is not exist. I don’t want to create thumbnail in front-end. Only want to get the thumbnail if it is exist. Is there a shortcut for this?
array(
'pattern' => 'api/tr(:all)',
'action' => function($uri) {
site()->visit($uri, "tr");
$page = page()->toArray();
$files = array();
foreach (page()->files() as $file) {
$file = $file->toArray();
//
// I need to access the thumbnail URL without create one
//
$file["thumb"]["url"] = $page["url"] . "/thumbs/" . $page["uid"] . "/";
$files[] = $file;
}
if (page()->files()->count() > 0) {
$page["files"] = $files;
}
$json = json_encode($page, JSON_UNESCAPED_UNICODE);
return response::json($json);
}
}
),