26

I have too many images to search visually, so I cannot open each one of them individually.

What do I have to do or install to show DDS image previews on nautilus?

I would like to preview webp too if possible.

31

Create files at /usr/share/thumbnailers with these names and content:

DDS

From here: Write to dds.thumbnailer:

[Thumbnailer Entry]
Exec=/usr/bin/convert -thumbnail x%s %i png:%o
MimeType=image/x-dds;

WEBP

First install webp: sudo apt-get install webp.
Based on this. Write to webp.thumbnailer:
sudo gedit /usr/share/thumbnailers/webp.thumbnailer.

[Thumbnailer Entry]
Exec=/usr/bin/dwebp %i -scale 100 100 -o %o
MimeType=image/x-webp;image/webp;

and restart nautilus after fully quitting it with nautilus -q.

As pointed by @PereJoanMartorell I had to remove the files inside ~/.cache/thumbnails/fail at least.

Note:
The problem with this webp approach is that all thumbnails will be 100x100 px.
But this script makes it work properly (and it can be highly simplified, see the answer below here https://askubuntu.com/a/1223606/46437, to not depend on ScriptEchoColor libs). Also the improved one based on it, for animated webp https://askubuntu.com/a/1322204/46437 (looks interesting, haven't tried it yet tho, just learned webp could be animated!). Obs.: on 18.04 and 20.04 it only works on nemo, on nautilus it is failing to generate the thumbnails but works to visualize'm.

4
  • 5
    If you replace the 100 with %s you'll get the appropriate size. Like this: Exec=/usr/bin/dwebp %i -scale %s %s -o %o – Liminal Jun 4 '16 at 11:09
  • @Liminal I had to update it to mime image/webp and I tested -scale %s %s but that was also giving me squared thumbnails of 256x256. On the other hand, the script calculates and gives the right proportional thumbnail size for x or y. ubuntu 16.04 here – Aquarius Power Aug 31 '17 at 1:25
  • 1
    There is a missing step here. You have to delete all cached thumbnails for Nautilus to be able to generate them again: rm ~/.cache/thumbnails/fail/gnome-thumbnail-factory/* rm ~/.cache/thumbnails/large/* rm ~/.cache/thumbnails/normal/* killall nautilus – Pere Joan Martorell Nov 29 '18 at 19:34
  • @pj.martorell interesting, I really dont remember having to do that, but apparently I probably did xD, btw, it could also be nautilus -q – Aquarius Power Nov 30 '18 at 20:25
12

A fairly comprehensive guide to preview WebP images on Nautilus & Nemo (based on the answer and the script suggested by @AquariusPower):

1. Install the webp package

sudo apt-get install webp

This package comes with the vwebp and dwebp tools which are going to be used to convert WebP images into smaller PNG thumbnails.

2. Check the MimeType of WebP files

  • Right-click a WebP image in File Manager (Nautilus, Nemo, etc.), choose Properties;
  • In the Basic tab, navigate to Type line and see what's in the brackets on the right. It is usually image/webp but it can also be image/x-webp, audio/x-riff, or in my case it's application/x-wine-extension-webp (because I use a windows image viewer with Wine to view WebP); Remember that MimeType, it's going to be used shortly after this.

3. Create a file with the name webp-thumbnailer-bin in /usr/bin

sudo nano /usr/bin/webp-thumbnailer-bin

Copy the following script (based on this) into the file (use Ctrl+C to copy, Ctrl+Shift+V to paste into nano window):

#!/bin/bash

strInFile="$1"
nMaxDimension="$2"
strOutFile="$3"

strInfo="`DISPLAY=NONE vwebp -info "$strInFile"`"
strSize="`echo "$strInfo" | grep Canvas | sed -r 's"Canvas: (.*) x (.*)"\1\t\2"'`"

nWidth="`echo "$strSize" | cut -f1`"
nHeight="`echo "$strSize" | cut -f2`"

if((nWidth>nHeight));then
    nNewWidth=$nMaxDimension
    nNewHeight=`bc <<< "scale=10;f=$nHeight*($nNewWidth/$nWidth);scale=0;f/1"`
else
    nNewHeight=$nMaxDimension
    nNewWidth=`bc <<< "scale=10;f=$nWidth*($nNewHeight/$nHeight);scale=0;f/1"`
fi

/usr/bin/dwebp "$strInFile" -scale $nNewWidth $nNewHeight -o "$strOutFile"

Press Ctrl+O (the letter O not the number zero 0) and Enter to save the file, and Ctrl+X to exit nano and return to the terminal.

This script inputs a WebP file, extracts its dimensions (width & height) with vwebp, and uses those values as inputs for dwebp to convert and scale the WebP file into a smaller PNG thumbnail with the original aspect-ratio.

Next, make the file executable:

sudo chmod +x /usr/bin/webp-thumbnailer-bin

4. Create a webp.thumbnailer file in /usr/share/thumbnailers

sudo nano /usr/share/thumbnailers/webp.thumbnailer

Copy the following contents into the file (use Ctrl+C to copy, Ctrl+Shift+V to paste into nano window):

[Thumbnailer Entry]
Exec=/usr/bin/webp-thumbnailer-bin %i 256 %o
MimeType=image/webp;image/x-webp;audio/x-riff;application/x-wine-extension-webp;
  • Remember the MimeType? If the type you checked earlier is not in the third line listed above, add it to the end of the line. Make sure to end the line with a semicolon (;).

  • Also, you can change 256 in the second line to 128 for even smaller thumbnails (though 256 is recommended as it's the default large thumbnail size for Nautilus).

Again, press Ctrl+O and Enter to save the file, and Ctrl+X to exit nano and return to the terminal.

5. (last) Clear thumbnail cache and regenerate thumbnails
Issue the following 4 commands in terminal, press Enter after each line:

rm ~/.cache/thumbnails/fail/gnome-thumbnail-factory/*
rm ~/.cache/thumbnails/large/*
rm ~/.cache/thumbnails/normal/*
nautilus -q
  • If you use nemo, the last command should be nemo -q.

  • Instead of using the terminal, you can delete the cache manually by going to ~/.cache/thumbnails and delete all 3 folders inside it (fail, large, normal).

  • Finally, reopen Nautilus or Nemo, all WebP images should be showing now.

Tested on: Ubuntu 16.04, 20.04; Linux Mint Cinnamon 19.3, 20.1.

Note: This method will generate thumbnails for static WebP images only. If you also want thumbnails for animated WebP, see Aistis's answer which added some interesting changes to the script.

3
  • Excellent. This one worked for me. Ubuntu 20.04.1 – PDG Feb 27 at 18:10
  • Thank you for sharing this :) I tried adding animated WebP thumbnail support in my answer iterating on your answer. I don't know if it's the best solution, but it seems to work. – Aistis Mar 9 at 7:54
  • This also works in LMDE 4. – JCCyC May 10 at 3:39
1

The other solutions didn't work on my Ubuntu 20.04 and (after some stracing) I found Nautilus runs the thumbnailers through bwrap these days.

However, /usr/bin/convert on my comp is symlinked to /etc/alternatives/convert which in turn is symlinked to /usr/bin/convert-im6.q16. The problem is, since /etc as a whole does not happen to be bound by bwrap as it's used by Nautilus, the final path will not be found.

This works for me but you may need to adjust the exact path of convert:

[Thumbnailer Entry]
Exec=/usr/bin/convert-im6.q16 -thumbnail %s %i %o
MimeType=image/x-webp;image/webp;image/x-dds;
1

ImageMagick has an option to convert webp and dds images. The full list of supported formats are here ImageMagick formats.

Remember for this to work you need first to install ImageMagick.

Now you can add a webp.thumbnailer file at /usr/share/thumbnailers with this lines:

[Thumbnailer Entry]
Exec=/usr/bin/magick %i -thumbnail %s %o
MimeType=image/x-webp;image/webp;image/x-dds;

And finally clear actual cached thumbnails with this commands:

rm ~/.cache/thumbnails/fail/gnome-thumbnail-factory/*
rm ~/.cache/thumbnails/large/*
rm ~/.cache/thumbnails/normal/*
nautilus -q
2
  • 1
    OP is about nautilus. Does that let nautilus to show webp? I don't see that happens. That said, +1 for mentioning ImageMagick. I didn't know it supports webp (even without the setting you posted. I'm on 20.04). – IsaacS May 13 at 12:50
  • @IssacS This instruction can slowly differ for your environment. So you need to do a little research. Where are thumbnailers, thumbnails cache and magick command located first. For me this instructions works well with webp images and they are shown in my file manager. – ustmaestro May 14 at 12:29
1

I followed @CalicoCat's instructions for generating thumbnails for static WebP images and made changes to the code in order to generate thumbnails for animated WebP images. Tested on Linux Mint 20.1. In @CalicoCat's 3rd step, change the code to the one bellow.

1. Edit the file (or create if missing) sudo nano /usr/bin/webp-thumbnailer-bin and replace the code with the one bellow

#!/bin/bash

strInFile="$1"
nMaxDimension="$2"
strOutFile="$3"

strInfo="`DISPLAY=NONE vwebp -info "$strInFile"`"
strSize="`echo "$strInfo" | grep Canvas | sed -r 's"Canvas: (.*) x (.*)"\1\t\2"'`"
strAnim="`echo "$strInfo" | grep VP8X | sed -r 's"VP8X: Found (.*) images in file \(loop count = (.*)\)"\1\t\2"'`"

nImgC="`echo "$strAnim" | cut -f1`"
nLoopCount="`echo "$strAnim" | cut -f2`"

nWidth="`echo "$strSize" | cut -f1`"
nHeight="`echo "$strSize" | cut -f2`"

if((nWidth>nHeight));then
    nNewWidth=$nMaxDimension
    nNewHeight=`bc <<< "scale=10;f=$nHeight*($nNewWidth/$nWidth);scale=0;f/1"`
else
    nNewHeight=$nMaxDimension
    nNewWidth=`bc <<< "scale=10;f=$nWidth*($nNewHeight/$nHeight);scale=0;f/1"`
fi

if [ "$nImgC" -eq 1 ]; then
    /usr/bin/dwebp "$strInFile" -scale $nNewWidth $nNewHeight -o "$strOutFile"
else
    /usr/bin/webpmux -get frame 1 "$strInFile" -o "$strOutFile".temp
    /usr/bin/dwebp "$strOutFile".temp -scale $nNewWidth $nNewHeight -o "$strOutFile"
    rm "$strOutFile".temp
fi

If you weren't following @CalicoCat's instructions before then you need to do the other steps bellow.

2. Next, make the file executable

sudo chmod +x /usr/bin/webp-thumbnailer-bin

3. Then create a webp.thumbnailer file in /usr/share/thumbnailers

sudo nano /usr/share/thumbnailers/webp.thumbnailer

4. Copy the following contents into the file

[Thumbnailer Entry]
Exec=/usr/bin/webp-thumbnailer-bin %i 256 %o
MimeType=image/webp;image/x-webp;audio/x-riff;application/x-wine-extension-webp;

5. Lastly, clear the thumbnail cache and regenerate thumbnails

For Nautilus:

rm ~/.cache/thumbnails/fail/gnome-thumbnail-factory/*
rm ~/.cache/thumbnails/large/*
rm ~/.cache/thumbnails/normal/*
nautilus -q

or for Nemo

rm ~/.cache/thumbnails/fail/gnome-thumbnail-factory/*
rm ~/.cache/thumbnails/large/*
rm ~/.cache/thumbnails/normal/*
nemo -q

Explanation of the changes I made from @CalicoCat's answer:

I added a variable nImgC that gets the count of frames from the WebP file (from the varaible strAnim). If there is only a single frame, then the WebP image is static. Else, the WebP image is animated. So we use webpmux to extract the first frame and then dwebp to save it as a usable thumbnail.

For the animated WebP image's thumbnail I'm using the very first frame because using any other frame can produce artefacts in the thumbnail (-get frame 1 is the first frame, and -get frame 0 is reserved for getting the last frame which often has pixels missing because of how some animations are compressed).

0

From Wikipedia Webp. As a derivative of the VP8 video format, it is a sister project to the WebM multimedia container format. So i tried totem-video-thumbnailer and it works.

[Thumbnailer Entry]
TryExec=/usr/bin/totem-video-thumbnailer
Exec=/usr/bin/totem-video-thumbnailer -s %s %u %o
MimeType=image/webp;image/x-webp; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.