I have a large library of PDF documents (papers, lectures, handouts) that I want to be able to quickly navigate through. For that I need thumbnails.
At the same time however, I see that the ~/.thumbnails
folder is piling up with thumbs I don't really need. Deleting thumbnail junk without removing the important thumbs is impossible. If I were to delete them, I'd have to go to each and every folder with important PDF documents and let the thumbnail cache regenerate.
I would love to be able to automate this process. Is there any way I can tell nautilus to pre-cache the thumbs for a set of given directories?
Note: I did find a set of bash scripts that appear to do this for pictures and videos, but not for any other documents. Maybe someone more experienced with scripting might be able to adjust these for PDF documents or at least point me in the right direction on what I'd have to modify for this to work with PDF documents as well.
Edit:
The response to this question has been quite overwhelming. Let me first thank everyone who participated in solving this. The question, its answers and all the discussion around it are a great example of how the collaborative effort of many parties can lead to an optimal solution. This is exactly what makes Linux and Open Source so great.
All of the provided answers would deserve the bounty I originally put up for this question. Still, there's only one bounty to award. I owe it to all future readers to choose the answer that solves the problem in the most efficient way. To determine which solution that is, I did a final test run, comparing the three scripts in compatibility, speed and output quality. Here are the results:
Thumbnailer 1, by rosch:
Compatibility: ✔ spaces in file name ; ✔ spaces in directory name ; ✘ freedesktop compliant
Speed: 95 PDFs in 12,6 sec
Quality: stock nautilus quality
Additional Perks: 1.) automatically skips files with preexisting thumbs ; 2.) No additional packages needed
Thumbnailer 2, by Martin Orda:
Compatibility: ✔ spaces in file name ; ✔ spaces in directory name ; ✘ freedesktop compliant
Speed: 95 PDFs in 70,0 sec
Quality: significantly better scaling than the stock images.
Additional Perks: 1.) automatically skips files with preexisting thumbs 2.) compatible with a wide range of image formats besides PDF 3.) platform-independent, does not rely on GNOME-components
Thumbnailer 3, by James Henstridge:
Compatibility: ✔ spaces in file name ; ✔ spaces in directory name ; ✔ freedesktop compliant
Speed: 95 PDFs in 10,8 sec
Quality: stock nautilus quality
Additional Perks: 1.) automatically skips files with preexisting thumbs 2.) compatible with all file formats that are identified by the preinstalled thumbnailers
All three scripts are excellent. Each has its distinct set of advantages and disadvantages. Rosch's solution works out of the box and might be the right choice for users with a minimal installation.
Marcin Kaminski created a very versatile script that works with a variety of file formats and is DE-independent. It excels at thumbnail quality but does so at the expense of speed.
In the end it was James' solution that fit my use case best. It's fast, versatile and offers the options to skip over files with preexisting thumbnails.
Overall winner: James Henstridge
Additional information: All three scripts are fully compatible with nautilus-scripts. You can easily install them following this tutorial.
Edit 2: Updated review with improved script by rosch.
Nautilus's thumbnailing routines actually come from the
libgnome-desktop
library, so it is possible to run the same thumbnailers outside of the file manager.The API is a little complex, but the following Python script should help:
Save this to a file and mark it executable. You may also need to install the
gir1.2-gnomedesktop-3.0
package if it is not already installed.After that, simply invoke the script with the files or folders you want to thumbnail as arguments. Thumbnails will be saved to
~/.thumbnails
where applications like Nautilus expect to find them.The script below should do the job. It uses
evince-thumbnailer
which - as far as I know - comes with every gnome installation and is the default thumbnailer.Save as
pdfthumbnailer.sh
and make it executable.Usage:
pdfthumbnailer.sh dir1 [dir2, ...]
Restriction:
evince-thumbnailer
is doing so. In other words..as long as nautilus does not regenerate the thumbnails the script can be used for the job.Notes:
evince-thumbnailer
andconvert
(from imagemagick): 3seconds forevince-thumbnailer
and 14seconds forconvert
.perl
, present in a default installationevince-thumbnailer
will simply output an error - muted with2>/dev/null
/usr/share/thumbnailers/evince.thumbnailer
to see a list of handled file types~/.cache/thumbnails
.More robust paths using
readlink
.Inspiration:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=683394
Got distracted for a while and rosch beat me to it :) Didn't know evince-thumbnailer existed (I'm not a Gnome user) but anyway, since I've already written it, here it goes. It requires imagemagick installed, check and install if not there with:
Save as
mkthumb.sh
(for instance),chmod +x mkthumb.sh
it and execute it with absolute paths as arguments (you can use -s as its first paramterer to skip generating thumbnails that already exist) i.e.:The script (I've modified it slightly to support most images, you can add more extensions if you need them):
It handles files with spaces in their names without issues.
I wrote a package that modified James' script to include multiprocessing and the option to recursively generate thumbnails. The package is
pip
-installable. Check here for installation instructions.An example of usage is:
-r
: recursively generate thumbnails-w
: number of cores to useThe thumbnail specification includes shared thumbnail repositories , which allow for pre-generating thumbnails to be distributed along with the associated files rather than have every user generate their own thumbnail. So in theory you could generate thumbnails and then add them to a shared repository thus removing the need to generate them in future if you cleared out your thumbnails directory, or moved them all to a different machine or whatever.
http://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html#DIRECTORY
This Ask Ubuntu page come up in the results of a search when I was trying to find out if any application supports shared thumbnail repositories. Sadly it appears that no application supports them.