I share my primitive script that I use to convert webp files to more traditional formats. This way they can be used anywhere in the default Ubuntu desktop, including working thumbnails in Nautilus.
Please note: I'm a hobbyist in this department, not a reliable expert. If you use / tinker on this script, that's your choice and responsibility.
The script depends on the webp
package being installed. It iterates over every *.webp file found in a given directory and its sub-directories recursively.
It converts to png, because that's my preference, but that can be changed in the line starting with dwebp
. Alternatively a variable could be introduced for the fileneme extension, to make it more ergonomic.
It also has a fallback action, because sometimes dwebp fails to convert: in my experience, sometimes files saved with .webp extension (by Firefox) are still just regular .jpg's or .png's inside. Then dwebp returns with an error. I figured most of the time, such files are .jpg's so in the fallback action I rename them as such. I think it would be very well possible to make the script find out the true format in such cases; but since it happens so infrequently, I just rather search for the the filename segment "webp-convert-fallback" in Nautilus, see if any of them fails to show a thumbnail, and try to rename them to other extensions manually (usually they are either .png's or .gif's then).
Also there was a challenge with filenames containing spaces, but I kept refactoring until it worked (on GNU bash version 5.0.17).
#!/bin/bash
CURRENTDIR=$(pwd);
# See https://stackoverflow.com/questions/4638874/how-to-loop-through-a-directory-recursively-to-delete-files-with-certain-extensi/15088473#15088473
# See https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#answer-9612560
find $CURRENTDIR -name '*.webp' -print0 | while read -d $'\0' file
do
# echo $file && continue
# See https://stackoverflow.com/questions/29505788/bash-dirname-basename-problems-with-spaces#answer-29505840
dirname=`dirname "$file"`
# echo $dirname && continue
# See https://linuxhandbook.com/basename/
basename=`basename "$file" .webp`
# echo $basename && continue
# See https://gist.github.com/earthgecko/3089509
rando=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
dwebp "${file}" -o ${dirname}/"${basename}".webp-convert-${rando}.png
# See https://linuxhint.com/check_command_succeeded_bash/
if [ $? -eq 0 ]; then
echo "========> DWEBP seemed successful:"
echo "========> Putting ${basename}.webp into the Trash."
# See https://askubuntu.com/questions/213533/command-to-move-a-file-to-trash-via-terminal
# gvfs-trash "$file" # Older standard.
gio trash "$file" # Newer standard.
else
echo "########> Failed converting $file"
mv "$file" "${dirname}/${basename}.webp-convert-fallback.jpg";
fi
done;
Additionally I quickly mention, that in Firefox it is (at least it was) possible to disable working with .webp images. This would work such way that Firefox would send such request headers to the web-servers that suggest that it cannot deal with webp files; normally it should trigger web-servers to send the image in a traditional format. (Search for "webp" in Firefox's about:config
page.)
But I stopped opting out from using webp's this way, because I have encountered a webshop that did not provide fallback images; seeing no images in a webshop made it pretty much unusable. Thus I had to give in, and let Firefox use webp's; that's how I ended up with the converting script.
gimp
and check.