I have created a plug-in to generate preview images of PDFs that are created in the panel during upload. Here is an example:
financialreport.pdf (-> template: pdf.yml)
financialreport.pdf.txt
financialreport.jpg (-> template: pdfcover.yml)
financialreport.jpg.txt
I use the preview image in the frontend for display. Both work perfectly.
In the panel, I would also like to use this image as a preview image to display the PDFs, as currently only the standard icon is displayed. Is that possible? I have not found a comparable solution for this in the forum.
I am not 100% sure that there are no guards somewhere in between that would prevent this, but if you try to use File blueprint | Kirby CMS somehow reliably pointing the query
suboption towards your generated JPG.
Thank you for your quick reply.
I had tried a plugin, but unfortunately no cover image is displayed in the panel.
<?php
Kirby::plugin('my/plugin', [
'fileMethods' => [
'customThumbnail' => function () {
$jpg = $this->parent()->file($this->name() . '.jpg');
return $jpg ? $jpg->url() : $this->icon();
}
]
]);
Blueprint:
query: "{{ file.customThumbnail }}"
Needs to be
image:
query: file.customThumbnail
and also the query should return a File
or an Asset
object, not a URL.
I have found a comparable solution here in the forum. However, this assumes that the name of the preview image is structured in this way:
image:
query: file.siblings.findBy("name", file.filename)
financialreport.pdf.jpg
financialreport.pdf.jpg.txt
In my plugin, ‘.pdf’ is removed from the name of the JPG, so the query query does not work.
financialreport.jpg
financialreport.jpg.txt
I could change my plugin now, but then I would have to regenerate all PDF preview images. Therefore, it is probably easier to change the query query. But how?
Why are you giving up on your custom file method if that works for your naming scheme?
Kirby::plugin('my/plugin', [
'fileMethods' => [
'customThumbnail' => function () {
return $this->parent()->file($this->name() . '.jpg');
}
]
]);
1 Like
The image preview now works with your modified plugin code.
Perfect! Many, many thanks!