ComputersAdding a gnome/nautilus thumbnailer

thumbnails for xfig files

NOTE: this only works for Gnome 2. For Gnome 3, see an update here

What it is:

a thumbnail is the little image that Nautilus (the file manager of Gnome) shows to represent the file. Most of file types has a standard thumbnailer, and you see a representation of the file such as a little image or a preview of the contents. This is quite useful, but less common filetypes do not have a preview, you just see a standard icon, the same for all of them.

I will explain how to add a thumbnailer for a new or unsupported file type. In that case we will add a script to prepare the preview of Xfig files (.fig).

How it works:

When trying to prepare the preview, Nautilus do the following (at least, I think…):
First step: it tries to find a preview computed before. To do this, it generate a hash for the file and looks into the directories under your $HOME/.thumbnails dir. If it find it, or find an entry that said the generation of the thumbnail failed before, it uses it (or a defualt icon) and stop searching. That means that, if you want to change the thumbnail generation and see the effects, you have to delete this “cache” under $HOME/.thumbnails.
Second step: if the type of the file is known, it generates (and saves in the cache) the preview. To see which is the type of a file, run

xdg-mime query filetype <file>

For example:

% xdg-mime query filetype xfig-thumbnailer.tar.gz

If the application type do not exist (blank or wrong answer), you can easily add your own filetype to the system.

Third step: if all this fail, it searches the “registry” (gconf database) for a couple of  entries called after the type; for example:



with a @ char in the place of the "/". If “enable” is true, it then call the command to generate the thumbnail. “command” is in the form

my_thumbnailer -s %s %u %o

and when calling it %s is substituted for the vertical size of the preview image, %u for the URL of the file (if it’s a local file, in the form of file:///path/to/file), and %o the output file where the preview (in PNG format) has to be stored.

The practical case: adding a thumbnailer for Xfig files.

Acknowlegment: this is mostly extracted/reworked from  here.

In the <package> file, you have all you need to add the thumbnails for your xfig file. Move it in a directory and uncompress it.

You will see 4 files: : this script moves the script to your $HOME/bin directory and enables the gconf entry that will run it. this script undoes what the previous did. Run it if you want to get rid of the thumbnailer.

xfig-thumb: this is the script that create the thumbnailer. It will need that you have xfig, fig2dev and imagemagick packages installed, otherwise it will fail (and you can see error messages in your $HOME/.xsession-errors file).

If you look at it, you will see that it creates a temporary file (there are some nice tricks there to safely delete it afterward), generate a PNG version of the file and then resizes it to the requested dimension and adds a little watermark text.

Download it!

thumbnailer for Xfig files
Title: xfig-thumbnailer.tar.gz (0 click)
Caption: thumbnailer for Xfig files
Filename: xfig-thumbnailer-tar.gz
Size: 2 KB

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>




This site uses Akismet to reduce spam. Learn how your comment data is processed.