Thumbnails improve efficiency. Having to open big XCF files each time to see their current status is a torture.
The thumbnailer-service interface may be the solution, but it seems one needs to be implemented and maintained for XCF thumbnails. As none seems to exists. To avoid having to write one, I'm looking for a simpler and faster to implement temporal solution.
The proposed solution of symlink the whole thumbnail/normal
directory to the one inside ~/snap
directory works, and each time you open and save a XCF file with GIMP, the thumbnail gets auto updated.
If, like my, you don't want to symlink the whole directory, I propose this other temporal solution: symlink individual thumbnails by mean of a Nautilus script. Note: requires to run the script for newly created XCF files, while already existing files will get their thumbnails auto updated.
The script:
#!/bin/bash
for file in ~/snap/gimp/common/.cache/thumbnails/normal/*
do
if [ -f $file ]
then
ln -s "$file" ~/".cache/thumbnails/normal/$(basename $file)"
fi
done
You can do the same for the thumbnails/large directory if needed.
Save to Nautilus script folder and you can run it every time you see XCF files without thumbnails. Recommended name "Update Thumbnails", no need for .sh extension, but turning on executable bit in file permissions is required.
The ln
command will just fail without harm when the symlink already exists.
Also, by using script-fu, it is possible to make gimp generate 128x128 PNG files, and save them to ~/.cache/thumbnails/normal
directory, from command line and without loading its interface.
But, while the following works:
$fileshort=$(basename "$file")
uri=$(urlencode -m "$fileshort") # urlencode requires install
uri="file://$uri"
thumbfilename=$(echo -n "$uri" | md5sum | awk '{print $1}')
thumbfilename=~/.cache/thumbnails/normal/$thumbfilename.png
gimp -i -b "(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE \"$file\" \"$file\")))
(drawable (car (gimp-image-active-drawable image)))
(cur-width (car (gimp-image-width image)))
(cur-height (car (gimp-image-height image)))
(ratio (min (/ 128 cur-width) (/ 128 cur-height)))
(width (* ratio cur-width))
(height (* ratio cur-height))
)
(gimp-image-scale image width height)
(file-png-save RUN-NONINTERACTIVE image drawable \"$thumbfilename\" \"$thumbfilename\" 0 9 1 1 1 1 1)
(gimp-image-delete image)
)" -b "(gimp-quit 0)"
You need to give a value to $file
somehow. For example, by iterating a directory.
The generation of a valid thumbnail name depends on urlencode
command, that's not present by default.
A valid thumbnail name is the result of obtaining the md5 hash of the filename in URI form "file://"
and appending the png extension to it.
The thumbnails won't auto update, having to run the script manually each time you want them to update.
There is the gimp-file-save-thumbnail
command for script-fu, but I had no luck with it. I didn't find the resulting thumbnail in my filesystem and the command doesn't seem to return anything.
Ideal solution: a GIMP extension that is aware that GIMP was installed by snap and saves thumbnails to ~/.cache/thumbnails/normal
each time you update an XCF file.
The problem: with script-fu may not be possible. As far as I know, those scripts needs to be invoked. You can register them as a menu item inside GIMP's interface, but you cannot have one reacting to file open
or file save
events.
Other possible solutions are:
Having a background bash or Python script monitor recently modified directories, and scanning them for XCF files. The script-fu above can be invoked to generate the thumbnails without showing the GIMP interface.
Challenge is to do it in the most optimal possible way.