33

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.

6 Answers 6

37

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 , to not depend on ScriptEchoColor libs). Also the improved one based on it, for animated webp (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.

5
  • 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, 2016 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 Aug 31, 2017 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 Nov 29, 2018 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 Nov 30, 2018 at 20:25
  • I've tested the script on Ubuntu 14.04 to 21.04 and it's been working fine for both Nautilus and Nemo, though. Could you go into more details about this "failing to generate the thumbnails but works to visualize'm"?
    – Calico Cat
    Mar 13 at 15:45
18

Some methods for previewing WebP images on Nautilus (GNOME Files) and Nautilus-based file managers (Nemo, Caja).

For Ubuntu 21.04 and later

  1. Install imagemagick

    sudo apt install imagemagick
    
  2. Get the MIME type of WebP images

    • Right-click a WebP file, select Properties.
    • On the Basic tab, take note of what is in the parentheses for the Type field. It is usually image/webp.
  3. Create a thumbnailer entry for WebP images

    • First, create a folder named thumbnailers in ~/.local/share.
      mkdir -p ~/.local/share/thumbnailers
      
    • Create a file named webp.thumbnailer in that folder.
      nano ~/.local/share/thumbnailers/webp.thumbnailer
      
    • Copy the following lines into the file (use Ctrl+C to copy, Ctrl+Shift+V to paste into nano window):
      [Thumbnailer Entry]
      Exec=/usr/bin/convert %i[0] -thumbnail %sx%s png:%o
      MimeType=image/webp;
      
    • Press Ctrl+O and Enter to save the file, and Ctrl+X to exit nano.

    Note: If the MIME type you got in step 2 is not in the third line listed above (the MimeType key), add it to the end of the line and optionally end the line with a semicolon (;).

  4. Clear old cached thumbnails and restart the file manager

    • First, fully close the file manager with one of these commands:
      nautilus -q
      nemo -q
      caja -q
      
    • Next, delete cached failed thumbnails:
      rm -r ~/.cache/thumbnails/fail
      
    • Optionally, delete all cached thumbnails:
      rm -r ~/.cache/thumbnails/*
      
    • Finally, reopen the file manager. WebP images should have their thumbnails now.

For Ubuntu 14.04 to 20.10

  1. Install webp

    sudo apt-get install webp
    

    This package provides the dwebp and webpmux tools, which will be used to convert WebP images into smaller PNG thumbnails.

  2. Get the MIME type of WebP images

    • Right-click a WebP file, select Properties.
    • On the Basic tab, take note of what is in the parentheses for the Type field. It is usually image/webp (but it could also be audio/x-riff or even application/x-wine-extension-webp).
  3. Create a thumbnailer script for WebP images

    • Create a file named webp-thumbnailer-bin in /usr/local/bin:
      sudo nano /usr/local/bin/webp-thumbnailer-bin
      
    • Copy this script (based on the methods from Script Echo Color and Aistis) into the file (use Ctrl+C to copy and Ctrl+Shift+V to paste into nano window):
      #!/bin/bash
      
      sInFile="$1"
      nSize="$2"
      sOutFile="$3"
      
      # Check whether the input image is an animated WebP
      sInfo="$(webpmux -info "$sInFile")"
      nAnimation="$(echo "$sInfo" | grep --count animation)"
      
      # Get the dimensions of the input image;
      # For a still image, they are the width and height
      # of the canvas;
      # For an animated image, they are the width and height
      # of the first frame of the image, which might be
      # different from those of the canvas.
      if [[ $nAnimation -eq 0 ]]; then
          sSize="$(echo "$sInfo" | grep Canvas | cut --delimiter=' ' --output-delimiter=$'\t' --fields=3,5)"
      else
          sSize="$(echo "$sInfo" | grep '^ *1:' | sed -r 's|^ *1: +([0-9]+) +([0-9]+) .*|\1\t\2|')"
      fi
      nWidth="$(echo "$sSize" | cut --fields=1)"
      nHeight="$(echo "$sSize" | cut --fields=2)"
      
      # Get the version number of `dwebp`
      sVersion="$(dwebp -version)"
      
      # Calculate new dimensions for the output thumbnail;
      # `dwebp` 0.5.0 and later support using 0 as a scaling
      # dimension;
      # With older versions, the smaller dimension has to be
      # manually calculated (using `bc`).
      if [[ $sVersion < 0.5.0 ]]; then
          if((nWidth>nHeight)); then
              nNewWidth="$nSize"
              nNewHeight="$(echo "scale=10;f=$nHeight*($nNewWidth/$nWidth);scale=0;f/1" | bc)"
          else
              nNewHeight="$nSize"
              nNewWidth="$(echo "scale=10;f=$nWidth*($nNewHeight/$nHeight);scale=0;f/1" | bc)"
          fi
      else
          if((nWidth>nHeight)); then
              nNewWidth="$nSize"
              nNewHeight=0
          else
              nNewHeight="$nSize"
              nNewWidth=0
          fi
      fi
      
      # Generate output thumbnail;
      # If the input image is an animated WebP, the first
      # frame is extracted with `webpmux` and used as input
      # for `dwebp`.
      # Versions of `dwebp` older than 0.4.1 do not support
      # reading WebP data from standard input, so the frame
      # has to be written to disk first.
      if [[ $nAnimation -eq 0 ]]; then
              /usr/bin/dwebp "$sInFile" -scale "$nNewWidth" "$nNewHeight" -o "$sOutFile"
      else
          if [[ $sVersion < 0.4.1 ]]; then
              /usr/bin/webpmux -get frame 1 "$sInFile" -o "$sOutFile".webp
              /usr/bin/dwebp "$sOutFile".webp -scale "$nNewWidth" "$nNewHeight" -o "$sOutFile"
              rm "$sOutFile".webp
          else
              /usr/bin/webpmux -get frame 1 "$sInFile" -o - | /usr/bin/dwebp -scale "$nNewWidth" "$nNewHeight" -o "$sOutFile" -- -
          fi
      fi
      
    • Press Ctrl+O and Enter to save the file, and Ctrl+X to exit nano and return to the terminal.
    • Make the file executable with:
      sudo chmod +x /usr/local/bin/webp-thumbnailer-bin
      

    Note: If you use Nemo or Caja, you can place this script somewhere in your home directory and run commands like the above without sudo, for example:

    mkdir -p ~/.local/bin
    nano ~/.local/bin/webp-thumbnailer-bin
    chmod +x ~/.local/bin/webp-thumbnailer-bin
    
  4. Create a thumbnailer entry for WebP images

    • First, create a folder named thumbnailers in ~/.local/share.
      mkdir -p ~/.local/share/thumbnailers
      
    • Create a file named webp.thumbnailer in that folder.
      nano ~/.local/share/thumbnailers/webp.thumbnailer
      
    • Copy the following lines into the file (use Ctrl+C to copy, Ctrl+Shift+V to paste into nano window):
      [Thumbnailer Entry]
      Exec=/usr/local/bin/webp-thumbnailer-bin %i %s %o
      MimeType=image/webp;audio/x-riff;
      
    • Press Ctrl+O and Enter to save the file, and Ctrl+X to exit nano.

    Note: If the MIME type you got in step 2 is not in the MimeType key above, add it to the end of the line and optionally end the line with a semicolon (;).

  5. Clear old cached thumbnails and restart the file manager

    • First, fully close the file manager with one of these commands:
      nautilus -q
      nemo -q
      caja -q
      
    • Next, delete cached failed thumbnails:
      rm -r ~/.cache/thumbnails/fail
      
    • Optionally, delete all cached thumbnails (if you previously used unoptimized thumbnailer entries or scripts that created large thumbnails):
      rm -r ~/.cache/thumbnails/*
      
    • Finally, reopen the file manager. WebP images should have their thumbnails now.

Notes

  • Thumbnails for both still and animated WebP images will be created with the above methods.

  • If you want the thumbnailer entry to be available to all users, place it in /usr/share/thumbnailers instead of ~/.local/share/thumbnailers:

    sudo nano /usr/share/thumbnailers/webp.thumbnailer
    
  • A GUI text editor like gedit can also be used to create and edit the thumbnailer entry, but if you plan to place the entry in /usr/share/thumbnailers, using nano is strongly recommended.

  • Some details for imagemagick's convert (skip this if you don't want to know all the nitty-gritty):

    [0] is specified so that, if the input image is an animated WebP, only the first frame is decompressed to a PNG thumbnail. Note that only imagemagick 6.9.10-68 and later (on Ubuntu 21.04 and later) support animated WebP encoding and decoding.

    -thumbnail %sx%s is used instead of just -thumbnail %s or -thumbnail x%s to ensure that both the width and height of the output thumbnail are at most 256 or 128 pixels, which is in line with the behavior of official thumbnailers. -thumbnail %s only limits the width and -thumbnail x%s only limits the height (see Image Geometry from ImageMagick).

    The format of the output image file is explicitly specified with png: because Nemo, Caja, and certain versions of Nautilus do not give output thumbnails a valid image extension. Without png:, convert would just creates files in the same format as the input (WebP in this case) for those file managers, leading to failed thumbnails.


Other methods

Notes:

  • Only thumbnails for still (non-animated) WebP images will be created when using one of the following methods.
  • The steps are similar to the methods above, so only the differences are presented.

Use gm (for Ubuntu 16.04 and later)

  • Install graphicsmagick which provides the gm tool:

    sudo apt install graphicsmagick
    
  • The contents of webp.thumbnailer:

    [Thumbnailer Entry]
    Exec=/usr/bin/gm convert %i[0] -thumbnail %sx%s png:%o
    MimeType=image/webp;
    

Use ffmpeg (for Ubuntu 16.04 and later)

  • Install ffmpeg

    sudo apt install ffmpeg
    
  • The contents of webp.thumbnailer:

    [Thumbnailer Entry]
    Exec=/usr/bin/ffmpeg -y -i %i -filter scale=%s:%s:force_original_aspect_ratio=1 -f apng %o
    MimeType=image/webp;
    

    Rationale: (skip this if you don't want to know the specifics)

    -y is specified to force ffmpeg to overwrite output thumbnails in the temporary directory. Without this option, failed thumbnails may not be regenerated.

    The output format is explicitly specified with -f apng because Nemo, Caja, and certain versions of Nautilus do not give output thumbnails a valid image extension. apng is actually for creating animated PNG files, but if the input is a still image, only a normal PNG is created.

    scale=%s:%s:force_original_aspect_ratio=1 is used so that the largest dimension of the output thumbnail is at most 128 or 256 pixels (which matches the behavior of official thumbnailers). See FFmpeg's documentation for the scale filter for more specifics.

Use totem-video-thumbnailer (for Ubuntu 14.04 and later)

  • Install totem and gstreamer1.0-plugins-bad

    sudo apt-get install totem gstreamer1.0-plugins-bad
    

    The totem package provides totem-video-thumbnailer, while the gstreamer1.0-plugins-bad package comes with the codecs needed by totem-video-thumbnailer to handle WebP images.

    Note: totem is the default video player on GNOME desktops, so it's pre-installed on Ubuntu.

  • The contents of webp.thumbnailer:

    • For Ubuntu 16.04 and later (or totem 3.11.90 and later): see Jan Broms's answer
    • For older Ubuntu releases (or older totem):
      [Thumbnailer Entry]
      Exec=/usr/bin/totem-video-thumbnailer -s %s --raw %u %o
      MimeType=image/webp;audio/x-riff;
      

    Rationale: (skip this if you don't want to know the whys and wherefores)

    totem-video-thumbnailer from totem older than 3.11.90 add borders (film strip overlay) to thumbnails by default. The --raw option is used to disable that feature.

Use dwebp (for Ubuntu 14.04 and later)

  • Install webp which provides dwebp

    sudo apt install webp
    
  • The contents of webp.thumbnailer:

    • For Ubuntu 18.04 and later (or dwebp 0.5.0 and later):
      [Thumbnailer Entry]
      Exec=/usr/bin/dwebp %i -resize %s 0 -o %o
      MimeType=image/webp;
      
    • For older Ubuntu releases (or older dwebp):
      [Thumbnailer Entry]
      Exec=/usr/bin/dwebp %i -o %o
      MimeType=image/webp;audio/x-riff;
      

    Note: If you use Nautilus on Ubuntu 18.04 or later or Caja on Ubuntu 20.04 or later, which do not automatically scales down thumbnails larger than the default thumbnail size (128x128 or 256x256 pixels), then you should employ one of the other methods (with which output thumbnails are properly resized).


Tested on

  • Ubuntu 14.04, 16.04, 18.04, 20.04, 20.10, 21.04
  • Linux Mint 20 Cinnamon
  • Ubuntu MATE 20.04
3
  • 1
    Excellent. This one worked for me. Ubuntu 20.04.1
    – PDG
    Feb 27, 2021 at 18:10
  • 1
    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, 2021 at 7:54
  • This also works in LMDE 4.
    – JCCyC
    May 10, 2021 at 3:39
2

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;
2

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"'`"
nImgC="`echo "$strInfo" | grep VP8X | sed -r 's"VP8X: Found (.*) images in file \(loop count = (.*)\)"\1"'`"

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 - | /usr/bin/dwebp -scale $nNewWidth $nNewHeight -o "$strOutFile" -- -
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. 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).

Thanks to @ColioCat for the help

Thanks to @ColioCat for cutting off 2 unnecessary cut calls and simplifying the code with a little pipping.

/usr/bin/webpmux -get frame 1 "$strInFile" -o - | /usr/bin/dwebp -scale $nNewWidth $nNewHeight -o "$strOutFile" -- -

The above code replaced the code bellow, where we first had to write our webpmux grabbed frame to disk, use it in dwebp to convert it to something usable by nautilus or nemo, and then remove it. As suggested, I'm leaving the original code snippet here.

    /usr/bin/webpmux -get frame 1 "$strInFile" -o "$strOutFile".temp
    /usr/bin/dwebp "$strOutFile".temp -scale $nNewWidth $nNewHeight -o "$strOutFile"
    rm "$strOutFile".temp
8
  • 1
    I can confirm that this works. Nice addition! Also, since we don't really need the loop count value, we could just use nImgC="`echo "$strInfo" | grep VP8X | sed -r 's"VP8X: Found (.*) images in file \(loop count = (.*)\)"\1"'`", which would save us 2 cut commands. But who knows, the loop count value might come in handy in the future.
    – Calico Cat
    Jun 21, 2021 at 9:58
  • @CalicoCat Nice. I'm still a greenhorn when it comes to Linux and bash. I just threw together something that seems to work and decided to share it as I had no luck finding an easy solution online. I don't think that loop count would ever be relevant to generating a thumbnail, but I still left it there for some reason. I'll update my answer to include your optimization if that's alright with you. Also, maybe you know of a way to directly pipe the output from webpmux to dwebp? IIRC, the only way to do it is to save the frame first on disk, and only then to convert it. I might be wrong tho
    – Aistis
    Jun 22, 2021 at 10:52
  • 1
    I'm also pretty new to Linux myself xD. Anyway, I just took a look at the official documents from Google and found that you can indeed pipe the output from webpmux to dwebp, like this: webpmux -get frame 1 "$strInFile" -o - | dwebp -scale $nNewWidth $nNewHeight -o "$strOutFile" -- -. I tested it but it seemed to only work on nemo. On nautilus or when used as a script, it did generate output files but failed to visualize them.
    – Calico Cat
    Jun 22, 2021 at 17:40
  • @CalicoCat It failed even when used as a script? As in a stand-alone bash script? For me it works fine on nemo and as a script. I can't say anything about nautilus but surely it should work as a script at the very least.
    – Aistis
    Jun 23, 2021 at 6:44
  • 1
    I just made a number of improvements to the script so it is faster (and supports more releases) now. You might want to take a look.
    – Calico Cat
    Oct 12, 2021 at 11:53
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, 2021 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, 2021 at 12:29
1

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.