Demystifying Thumbnails
Part 1 of my series on Tips and Tricks for the Linux Desktop
But why?
Have you ever opened a folder of pictures and had to wait for your file manager to sequentially generate the thumbnails? Does it bug you when sometimes the previously generated thumbnails somehow resets and you have to sit through the thumbnail generation AGAIN??
Well, I have a sizable collection of about 80,000 photographs taking up about 1.1 TB and I don’t want to waste time waiting for thumbnails to load when I am trying to find a particular photo. So, I have been getting to grips with how thumbnails work in an attempt to make culling through my photos faster. I am happy to say that after stumbling though a part of the Linux Desktops that is rarely trodden, I have been been able to get there in the end 😎️
Continue reading if you want to know how thumbnails work on Linux and to pick up some trick to managing photos…
The Thumbnail Cache
For Linux users there is an actual “Thumbnail Managing Standard” defined by the freedesktop.org. All major Linux desktop projects like GNOME, KDE and Xfce follow these standards.
This standard outlines:
- Specifications of the file previews (thumbnails) : format, resolution, meta data format, etc
- How and where to store them : location, file name
- Mechanisms for these previews to be shared by many applications : concurrent access, handling failures
This standard is pretty elegant in that it allows for may specialized apps to generate previews that all other apps can use. For example a proprietary CAD app can generate thumbnails for it’s files and still have the thumbnails for them be displayed when viewed via a File Manager.
Here is what you need to know about these thumbnails
- Thumbnail cache location : $HOME/.cache/thumbnails
- There are three folders inside : normal, large & fail
- normal folder has 128x128 resolution thumbnails
- large folder has 256x256 resolution thumbnails
- By default your File Manager (GNOME Files / Nautilus in my case) would generate “normal” thumbnails
- The thumbnail files are in PNG format
- The file names of the thumbnails correspond to the MD5 hash of it’s canonical absolute URI (e.g. file:///home/ruvi/pic.jpg)
- The fail folder has files sorted in to folders of app names that have attempted to generate a preview and failed. This helps stop an app from repeatedly trying to generate a thumbnail when it’s perhaps corrupted and not doable.
- The thumbnail file’s metadata includes information about the original file’s modified date so that it knows when the thumbnail needs to be re-generated when changes happen to the original file
Quick note on the Windows Thumbnail Cache; modern Windows operating systems use a similar thumbnail cache stored at “%userprofile%\AppData\Local\Microsoft\Windows\Explorer”. It is only created and used by Explorer.exe though. Older Windows versions had a distributed thumbnail cache, where it created “Thumbs.db” files in every folder.
Now that we have some idea of how thumbnails work, let’s see what you need to do to make them load faster.
Tip #1 : Generating thumbnails on demand
Use this cool multi-threaded tool : https://github.com/difference-engine/thumbnail-generator-ubuntu to generate thumbnails using the Python bindings to GTK/GNOME-Desktop libraries. One of the main drawbacks of relying on your File Manager to generate thumbnails is that it is single threaded. So, depending on how many cores you have and how fast your storage is, this tool can generate thumbnails of your photo library an order of magnitude faster!
You can optionally use my folk (https://github.com/ruvindad/thumbnail-generator-ubuntu) of the above mentioned tool to generate “large” thumbnails. This creates 256x256 thumbnail files instead of the default 128x128 files. GNOME Files app applies a lot of anti-aliasing and smoothing to it’s thumbnail rendering, so i haven’t seen an appreciable difference in the thumbnail quality. If you don’t mind the extra disk usage (2GB vs 8GB in my case), try my folk and @ me know if you do notice any difference.
After you generated the thumbnails, your thumbnails will load almost instantly when you view them from your File Manager 😎️
Tip #2 : Configuring GNOME Housekeeping
After generating the thumbnails on demand, I ran into a problem where my thumbnail cache was getting purged every time I rebooted my computer! This was particularly frustrating because this was one of those rare moments when search results came up empty. I had to resort to use the auditd tool to figure out which process deleted my thumbnails and then was able to trace it to the “housekeeping” module of the “GNOME-settings-daemon”.
While there is no way to adjust this behavior via the Settings app, I was able to find relevant dconf settings. To adjust these low-level configurations, first install dconf-editor (sudo apt install dconf-editor). Then navigate to the following path: /org/gnome/desktop/thumbnail-cache
Here you will see that there is a maximum age (180 days) and size limit (512MB) to expire the thumbnail cache. The default 512MB size limit is way too small for my image library and that limit is what was triggering the housekeeping service to purge my thumbnail cache. Increase these limits to suite your needs or simply set them to -1 to disable it all together.
Tip #3 : GNOME Files tweaks
Use dconf-editor to change the following thumbnail related configs in your file manager
- /org/gnome/nautilus/preferences/thumbnail-limit : Thumbnail generation is limited to files smaller than 10MB by default. Increase this to something like 200MB so that thumbnails are generated for your high megapixel photos
- /org/gnome/nautilus/preferences/show-image-thumbnails : If you work with network attach storage and want to generate thumbnails for them too, adjust this config to “always”
Tips #4: GNOME sushi
sudo apt install gnome-sushi
Gnome sushi let’s you press spacebar to quickly open preview of a file; similar to how it works on Finder/MacOS.
That’s it folks!