How to preview DDS and WEBP images on nautilus?
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.
Solution 1:
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.
Solution 2:
A fairly comprehensive guide to previewing WebP images on Nautilus (GNOME Files) and Nautilus-based file managers (Nemo, Caja).
Originally, this answer only described using dwebp
to create thumbnails for WebP images, based on the answer and the script suggested by Aquarius Power. After some research, I have found more methods for previewing WebP plus various details about the thumbnailing process that can make the methods of other users work not only on Nautilus but also on Nemo and Caja. This answer is then updated to discuss all of those methods in detail.
Method 1: Use dwebp
& webpmux
-
Install
webp
sudo apt install webp
This package provides the
dwebp
andwebpmux
tools, which will be used to convert WebP images into smaller PNG thumbnails. -
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
orimage/x-webp
, but it could also beaudio/x-riff
(on older releases like Ubuntu 14.04) or evenapplication/x-wine-extension-webp
(if you use a Wine application to open WebP images on older releases).
Alternatively, you can use
xdg-mime
. For example, to get the mime-type ofexample.webp
in~/Pictures
, issue this command:xdg-mime query filetype ~/Pictures/example.webp
-
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
Notes:
- This script creates thumbnails for both still (non-animated) and animated WebP images.
- I originally put the script in
/usr/bin
, but as this answer suggested, it is safer to place it in/usr/local/bin
. - If you use Nemo or Caja, you can actually place the script somewhere in your home directory (e.g.
~/.local/bin
) and run commands like the above withoutsudo
. If you use Nautilus, however, you can only do so with Nautilus usinglibgnome-desktop
older than 3.28.2. This is becauselibgnome-desktop
3.28.2 and later implement thumbnailer sandboxing and do not allow for the execution of any thumbnailer programs or scripts in the home directory by default. To get the version number oflibgnome-desktop
in use, run this command:apt list --installed | grep libgnome-desktop | cut -d ' ' -f 2 | cut -d '-' -f 1
- Create a file named
-
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;
- Press Ctrl+O and Enter to save the file, and Ctrl+X to exit
nano
.
Notes:
- 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 (;
). - If you want thumbnails for WebP images to be available to all users, place the thumbnailer entry 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
, usingnano
is strongly recommended.
- First, create a folder named
-
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.
- First, fully close the file manager with one of these commands:
Method 2: Use dwebp
-
Install
webp
(which providesdwebp
)sudo apt install webp
-
Get the mime-type of WebP images (see Use dwebp & webpmux, step 2)
-
Create a thumbnailer entry for WebP images (see Use dwebp & webpmux, step 4 for details)
The contents of
~/.local/share/thumbnailers/webp.thumbnailer
withdwebp
as the thumbnailer program:- 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;
Notes:
-
dwebp
does not support animated WebP decoding, so these thumbnailer entries will only create thumbnails for still WebP images. - 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 method 1 (with which output thumbnails are properly resized).
- For Ubuntu 18.04 and later (or
-
Clear old cached thumbnails and restart the file manager (see Use dwebp & webpmux, step 5)
Method 3: Use convert
The convert
tool (from imagemagick
) can be used to create thumbnails for WebP images on Ubuntu 16.04 and later. The idea of using convert
as a thumbnailer program for WebPs came from Tiana's and ustmaestro's answers.
-
Install
imagemagick
which providesconvert
sudo apt install imagemagick
Note:
convert
can handle WebP images natively on Ubuntu 20.04 and later; however, on older releases such as Ubuntu 18.04 and 16.04, WebP compression and decompression are actually delegated tocwebp
anddwebp
from thewebp
package. As a result, if you are on those older releases, you also have to installwebp
:sudo apt install webp
-
Get the mime-type of WebP images (see Use dwebp & webpmux, step 2)
-
Get the version number of
libgnnome-desktop
used by Nautilus and fix sandboxing issues if needed (skip this step if you use Nemo or Caja)Issue this command to get the version number of
libgnome-desktop
:apt list --installed | grep libgnome-desktop | cut -d ' ' -f 2 | cut -d '-' -f 1
If the result is 3.28.2, then you have to do the following (otherwise proceed to the next step):
- Create a file named
bwrap
in/usr/local/bin
:sudo nano /usr/local/bin/bwrap
- Copy the contents of this script (by Nicolas Bernaerts) into the file (use Ctrl+C to copy and Ctrl+Shift+V to paste into
nano
window). - Save the file and exit
nano
(press Ctrl+O, Enter, Ctrl+X). - Make the file executable with:
sudo chmod +x /usr/local/bin/bwrap
Rationale:
convert
needs certain files in/etc
and/var
in order to work properly, but Nautilus that useslibgnnome-desktop
3.28.2 (on Ubuntu 18.04 specifically) does not mount those directories on the sandbox, resulting in failed thumbnails. Thebwrap
script above fixes the issue by adding the directories needed byconvert
to the sandbox (see this article for more details). - Create a file named
-
Create a thumbnailer entry for WebP images (see Use dwebp & webpmux, step 4 for details)
The contents of
~/.local/share/thumbnailers/webp.thumbnailer
withconvert
as the thumbnailer program:[Thumbnailer Entry] Exec=/usr/bin/convert %i[0] -thumbnail %sx%s png:%o MimeType=image/webp;
Rationale:
- 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 the.png
extension. Withoutpng:
,convert
would just creates files in the same format as the input (WebP in this case) for those file managers, leading to failed thumbnails. -
-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). -
[0]
is specified so that, if the input image is an animated WebP, only the first frame is decompressed to a PNG thumbnail.
Notes:
- With
imagemagick
6.9.10-68 or later (on Ubuntu 21.04 and later), which supports animated WebP encoding and decoding, this thumbnailer entry will create thumbnails for both animated and non-animated WebP images. With older versions, however, only thumbnails for still WebP images will be created. - If you are using Nautilus with
libgnnome-desktop
3.36.1 (on Ubuntu 20.04 specifically), then/usr/bin/convert-im6.q16
must be used instead of/usr/bin/convert
:
This is because, with this version ofExec=/usr/bin/convert-im6.q16 %i[0] -thumbnail %sx%s png:%o
libgnnome-desktop
,/usr/bin/convert-im6.q16
is visible to the sandbox, while/usr/bin/convert
is not (Tiana also noticed this).
- The format of the output image file is explicitly specified with
-
Clear old cached thumbnails and restart the file manager (see Use dwebp & webpmux, step 5)
Method 4: Use gm
gm
(from graphicsmagick
) supports WebP on Ubuntu 16.04 and later.
-
Install
graphicsmagick
which provides thegm
toolsudo apt install graphicsmagick
-
Get the mime-type of WebP images (see Use dwebp & webpmux, step 2)
-
Create a thumbnailer entry for WebP images (see Use dwebp & webpmux, step 4 for details)
The contents of
~/.local/share/thumbnailers/webp.thumbnailer
withgm
as the thumbnailer program:[Thumbnailer Entry] Exec=/usr/bin/gm convert %i[0] -thumbnail %sx%s png:%o MimeType=image/webp;
Note:
gm
does not support animated WebP files, so this thumbnailer entry only creates thumbnails for non-animated WebP images. -
Clear old cached thumbnails and restart the file manager (see Use dwebp & webpmux, step 5)
Method 5: Use totem-video-thumbnailer
As suggested by Jan Broms, totem-video-thumbnailer
can also be used to thumbnail WebP images.
-
Install
totem
andgstreamer1.0-plugins-bad
sudo apt install totem gstreamer1.0-plugins-bad
The
totem
package providestotem-video-thumbnailer
, while thegstreamer1.0-plugins-bad
package comes with the codecs needed bytotem-video-thumbnailer
to handle WebP images.Note:
totem
is the default video player on GNOME desktops, so it's pre-installed on Ubuntu.gstreamer1.0-plugins-bad
is not pre-installed, however, probably because it's only listed as a suggested package fortotem
. -
Get the mime-type of WebP images (see Use dwebp & webpmux, step 2)
-
Create a thumbnailer entry for WebP images (see Use dwebp & webpmux, step 4 for details)
The contents of
~/.local/share/thumbnailers/webp.thumbnailer
withtotem-video-thumbnailer
as the thumbnailer program:- 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:
totem-video-thumbnailer
fromtotem
older than 3.11.90 add borders (film strip overlay) to thumbnails by default. The--raw
option is used to disable that feature.Note:
totem-video-thumbnailer
does not support animated WebP, so this thumbnailer entry will create thumbnails for still WebP images only. - For Ubuntu 16.04 and later (or
-
Clear old cached thumbnails and restart the file manager (see Use dwebp & webpmux, step 5)
Method 6: Use ffmpeg
ffmpeg
supports WebP decoding on Ubuntu 16.04 or later.
-
Install
ffmpeg
sudo apt install ffmpeg
-
Get the mime-type of WebP images (see Use dwebp & webpmux, step 2)
-
Create a thumbnailer entry for WebP images (see Use dwebp & webpmux, step 4 for details)
The contents of
~/.local/share/thumbnailers/webp.thumbnailer
withffmpeg
as the thumbnailer program:[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:
-
-y
is specified to forceffmpeg
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
(see Use convert, step 4).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 thescale
filter for more specifics.
Note:
ffmpeg
does not support animated WebP images, so this thumbnailer entry only creates thumbnails for still WebP images. -
-
Clear old cached thumbnails and restart the file manager (see Use dwebp & webpmux, step 5)
Summary
Tested on → | Ubuntu 14.04 | Ubuntu 16.04 | Ubuntu 18.04 | Ubuntu 20.04; Linux Mint Cinnamon 20; Ubuntu MATE 20.04 | Ubuntu 20.10 | Ubuntu 21.04 |
---|---|---|---|---|---|---|
dwebp & webpmux | ✔️animated
|
✔️animated
|
✔️animated
|
✔️animated
|
✔️animated
|
✔️animated
|
dwebp | ✔️ | ✔️ | ✔️-resize 0
|
✔️-resize 0
|
✔️-resize 0
|
✔️-resize 0
|
convert | ❌️ | ✔️webp
|
✔️webp bwrap
|
✔️convert-im6.q16
|
✔️ | ✔️animated
|
gm | ❌️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
totem-video-thumbnailer | ✔️--raw
|
✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
ffmpeg | N/A | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |