Since we can now override thumbnails using External Tools, I was thinking that doing something similar through scripting could also be a neat addition to Opus's current arsenal.
I got the idea from a Script add-In I'm currently updating, related to ebooks. I noticed that in some cases we don't actually need to generate a new thumbnail image; we just need to "tell" Opus to use an existing image as the thumbnail.
What do you think would be the best approach for this? Perhaps through a new scripting event, or by adding a new ScriptColumn type (e.g. thumbnail)?
One possible approach would be:
Define the extensions/filegroups in the same way as with External Tools.
Instead of Opus providing an output filepath, the script returns the path to the image that Opus should use.
The script would obviously be responsible for making sure there's a valid image at that path.
One potential downside is that it might be difficult to tell which script is providing a particular thumbnail, or to disable individual script-based thumbnailers.
Another benefit would be the ability to do selective thumbnailing this way.
For example, a script that declares a thumbnailer could return something like default, telling Opus to use the regular default thumbnail for that file.
That would allow a thumbnailer to provide a custom thumbnail when certain conditions are met, such as the file's path or other properties.
I guess an OnGenerateThumbnail() method might make sense? It could take the input filename as an argument, and return a path to the converted image, a Blob/Image object, or false if it doesn't support the format.
Not sure if there'd need to be a way to specify in advance the filetypes it handles - would have to see what the impact on performance is if there are a few thumbnail scripts installed.
I would say is fine.
Another approach that could work would be to define it as another column in OnAddColumns(), with a thumbnail type. In that case, you could use the multicol option (since scripts of this kind would very likely want to define other columns as well). In this case, perhaps the script could declare a name for the thumbnail as well?
As for which approach would have better performance, I'm not really sure. I'll leave that decision to your experience.
One point worth discussing is how the user would know where a thumbnail comes from. And what happens if more than one script tries to provide a thumbnail for the same file or file type? Would there be a separate section to manage these?
I revived an old script I made for getting ebook metadata in Opus (you can use columns from Calibre, etc), in which I can handle covers for .epub files through External Tools using a helper, but supporting other formats (basically any file that has a companion .opf and cover.jpg) is where there's currently no way to do it. That's when I thought that having a script thumbnailer could be handy.
I've also noticed something that could potentially be an issue: since thumbnails are cacheable, they don't automatically get regenerated when the thing that created them changes. So if a file's thumbnail was generated one way and you later want to generate it differently, you have to clear the cache first. Since there's currently no way to clear the cache for just a single file or path (please correct me if I'm wrong on this), you'd have to wipe the entire thumbnail cache, which can be inconvenient in many cases.