Hi!
Thumbs generation is a bit “magic” in Kirby3 and I am trying to explain how I think it works.
Please correct me if my steps below are wrong!
The first part of thumb generation:
When using $file->thumb() , you are calling the thumb method of the file class. This method is defined in the FileModifications trait.
Inside this method the file::version component is called (here)
The file::version component checks if an image with the defined specifications already exists, otherwise prepares the job file for lazy thumbnail creation (they are saved in the media/… folder in a .jobs subfolder for each page).
The second part of thumb creation:
Via routing Kirby realizes that you want to load an image from the media folder that has not yet been generated. You end up in the Media class static thumb method. The job file is used to get the specifications.
which finally uses the Darkroom classes or your own thumbnail creation code.
Long story short: Your pdf thumb generation fails in the second step of part 1. file::version checks if a file is resizable and a pdf is not.
You’ll need to adjust the file::version component aswell or use another solution, e.g. an after upload hook.
So, I ended up in a simple field method that saves a preview as siblings of the original file. Like this, it became a regular image that you can chain or use as a preview for the original PDF in templates or panel.
But, as this, it is also listed when calling $page->files() and displayed in the panel page files section if you use templates on other files to be able to filter this list.
I would rather save the preview in the media folder so this file cannot be listed in the $page->files() method… But, if saving the preview in the media folder returns a file to display in front end, I didn’t manage to allow it to be chained like a regular Kirby File. Actually, you can’t even make a thumbnail of it.
Am I right to assume that with your solution, Imagick parses the whole PDF even though it makes the thumb from the first page? That could be quite a problem for larger files (got some documents with 500+ pages).
I’m currently implementing this library to circumnavigate performance issues:
Hello everyone !
I’m also interested for an automatic jpg/png thumbnail creation for my PDF’s… Anyone got a solution please ?
My programming skills are small… and I’m a “rookie” kirby user…
Thanks a lot !