WebP files are one of modern web technologies, a compact and space-efficient file format developed by Google in recent years that is friendly to web services. While it may be convenient for site administrators, support is still not complete in general. For example, some sites only allow uploads in JPG/PNG format, and you cannot upload WebP format files directly.
There are two main methods to convert WebP files to JPG/PNG files.
Convert with ffmpeg
ffmpeg is probably installed for most people. Convert WebP files to JPG files as follows:
ffmpeg -i file.webp out.jpg
If you haven’t installed it yet, install it:
sudo apt update ; sudo apt install ffmpeg -y
If you don’t have a WSL or Linux environment and want to install it on Windows, using choco is a good option. For installation and usage of chocolatey, please refer to other articles. Please use this blog’s search function.
choco install ffmpeg
Convert with dwebp
This method uses the dwebp command included in the webp package for WebP conversion.
Install webp:
sudo apt update ; sudo apt install webp -y
Use it as follows for conversion:
dwebp file.webp -o abc.png
By the way, the “d” in “dwebp” stands for “decompress”.
Note that conversion with ffmpeg is good for jpg files, but there seems to be an issue where output files become large for png. For png conversion, it’s better to use dwebp.
It is good for jpg image, but png format is very large
(Reference)
Convert All WebP Files in a Folder to JPG
Below is an application usage example. With the following script, let’s convert all WebP files in a folder to JPG.
for i in *.webp; do ffmpeg -y -i "$i" "$(basename "${i%.*}").jpg"; done;
Instantly Convert to JPG When WebP Files Are Added to a Folder
This is an application usage example.
I wrote a simple script that instantly converts WebP files to JPG and deletes the WebP files when they are added to a folder. It’s convenient, so please use it.
Save the following script to tmp.sh:
for i in *.webp; do ffmpeg -y -i "$i" "$(basename "${i%.*}").jpg"; done; rm *.webp
Use nodemon to detect changes in the folder and execute the tmp.sh script as needed:
nodemon -e webp --exec ./tmp.sh
If you haven’t installed nodemon yet, install it. For installation of node.js and npm using nvm, please refer to other articles. Please use this blog’s search function.
npm i -g nodemon