- Simple way to Convert WebP Images to PNG and JPG/JPEG in Linux
- Steps to Convert a WebP Image to PNG, JPG, or JPEG
- Use dwebp Command to Convert WebP Image
- Use ffmpeg Command to Convert WebP Image
- How to Convert WebP Images to PNG and JPEG in Linux
- Problem Statement
- WebP libwebp Library
- Installing libwebp Library on Linux
- Converting WebP Image to PNG in Linux
- Converting WebP Image to JPEG in Linux
- How to View WebP Image and Convert WebP to PNG or JPEG in Linux
- Enable WebP Support to GNOME Image Viewer in Linux
- View WebP Images Using gThumb Image Viewer in Linux
- Convert WebP Images to PNG or JPEG Using dwebp Utility
- Convert PNG or JPEG to WebP Using cwebp Utility
- Convert WebP Images to PNG or JPEG Using XnConvert
Simple way to Convert WebP Images to PNG and JPG/JPEG in Linux
Almost every website now accepts WebP images due to their low size, which reduces image size by 25 to 34% compared to JPGs without much compromising the image quality.
But there are still some sites that will not allow you to upload a WebP image to their platform, and because of that, you need to convert the image to jpg or png.
For the conversion of a WebP image, you can take a screenshot of the image, or else you can use some online tool that is available in the public domain.
However, I don’t do this all because I know the command that can easily convert the WebP image to formats like PNG, JPEG/JPG, and so on.
So let me show you how you can use the dwebp and ffmpeg commands to convert WebP images to PNG, JPG, and JPEG format.
Steps to Convert a WebP Image to PNG, JPG, or JPEG
There are two common commands that you can use in Linux to convert WebP images, which are as follows:
- dwebp: can be used to convert WebP images into formats like pam, ppm, bmp, tiff, pgm, yuv, and the default, png.
- ffmpeg: is one of the versatile tools that can be used in several ways to manipulate video and audio, including converting, compressing, and editing multimedia files.
Use dwebp Command to Convert WebP Image
As I said, dwebp is a part of the libwebp library, so when you install libwebp, two interesting tools get installed, like cwebp and dwebp .
cwebp is used to convert a png, jpg, or any other format image into webp, and on the other hand, dwep is used to convert a webp image back to its original format.
Now that you understand which tool we are going to use for converting WebP images, please bring up the system terminal and install it by running the following command:
$ sudo apt install webp // Ubuntu and Debian $ sudo yum install libwebp // AlmaLinux, Fedora $ sudo pacman -S libwebp // Arch Linux
Once the installation is complete, you can now start converting WebP images to PNG format.
The syntax of the dwebp command is simple; you need to first specify the path where the webp image is located, use the -o parameter, and provide the output filename with the .png extension.
$ dwebp input_webp_image.webp -o output.png
Now let me use the above code syntax to convert one of the WebP images to PNG by following the above syntax:
$ dwebp sample_1.webp -o output.png
Once you get the output, you can check the file information by using the file command, which will confirm the format of the output file.
And with the below screen snip, you can see how I have converted sample_1.webp to output.png.
Sometime you may need to convert more than one WebP image to PNG.
If that is the case, then the above command will not be beneficial, so you can use the for loop to loop through all the webp images in a directory and convert them to png format one by one.
Now go back to the terminal and execute the following command to convert all the WebP images to PNG format.
$ for FILE in *.webp; do dwebp "$FILE" -o "$.png"; done
The dwebp command will work fine until you don’t want to convert images into jpg format.
Use ffmpeg Command to Convert WebP Image
Alternatively, you can use the ffmpeg command to convert WebP images to PNG, JPG, or JPEG format.
To get started with the conversion, open up your terminal window and execute the following command to check the presence of ffmpeg on your system:
$ ffmpeg -version
If the above command prints the version with configuration information, then you can skip the installation part.
How to Convert WebP Images to PNG and JPEG in Linux
Webp image formats are natively supported on reputable web browser platforms like Google Chrome, Opera, Brave, Edge, Safari, and Firefox. So what makes Webp image file format so unique? The lossless images associated with WebP image file formats tend to be 26% smaller than PNG images and 25%-34% smaller than JPEG images. They also have impeccable support for transparency (alpha channel).
For one reason or another, you might need to convert raw WebP image files to PNG and/or JPEG image file formats. It could be for compatibility reasons with a project you are working on or for personal curiosity.
This article is here to investigate the possible approaches to achieving the latter stated objective.
Problem Statement
Consider the existence of the following raw WebP image file on a Linux operating system environment. We can further use the ls command to determine the file size properties associated with this WebP image file.
On estimate, the size of the image file represented by the above screen capture is roughly 30.3 KB. Therefore, since WebP image files are estimated to be much smaller in comparison to PNG and JPEG image files, converting them to these image file formats should result in relatively bigger image file sizes.
WebP libwebp Library
The WebP image file format is associated with libwebp which is a lightweight encoding and decoding library. Also, this library is accompanied by two very useful command-line tools namely cwebp and dwebp.
In summary, the cwebp command-line tool is effective in compressing and inputting image file to a WebP file. On the other hand, the dwebp command-line tool is the complete opposite of the cwebp tool. It generally compresses an input WebP file to an image file.
In this article, we will be more interested in the dwebp command-line tool to successfully convert our sample raw WebP image file to PNG and JPEG image files.
Installing libwebp Library on Linux
In order to use the dwebp tool to convert WebP images to PNG and JPEG images, we need to install the libwebp library on our Linux systems since it is pre-packaged with this tool.
$ sudo apt install webp [On Debian, Ubuntu and Mint] $ sudo yum install libwebp [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a media-libs/libwebp [On Gentoo Linux] $ sudo pacman -S libwebp [On Arch Linux] $ sudo zypper install libwebp [On OpenSUSE]
As per the man page, the standard syntax for using dwebp tool is:
$ dwebp [options] input_file.webp -o final_image_file.image_extension
You will also discover that the manual page of dwebp tool is associated with multiple useful command options like -crop for cropping the final image and -resize/-scale for determining the width and height of the final image.
Converting WebP Image to PNG in Linux
To convert our raw WebP image to PNG image, implement:
$ dwebp image.webp -o final.png
In terms of size comparison, the PNG file should be bigger:
Converting WebP Image to JPEG in Linux
To convert our raw WebP image to JPEG image, implement:
$ dwebp image.webp -o final.jpeg
The JPEG file should also be bigger that the original WebP file.
We have successfully demonstrated how to use the libwebp WebP library to convert WebP images to PNG and/or JPEG images via the dwebp command-line tool.
Hope this article guide was useful. Feel free to leave a comment or feedback.
How to View WebP Image and Convert WebP to PNG or JPEG in Linux
Developed by Google with the main objective of making loading times faster across the internet, WebP (pronounced “weppy”) is a modern image format and a replacement for JPEG, PNG, and GIF file formats.
Compared to other image formats, webp offers superior lossless and lossy compression for images on the web. WebP is one of the many projects by Google that supports its mission to make the web faster.
On Ubuntu-based and RHEL-based Linux distributions, the default image viewer does not support .web format images.
If you try to view WebP image with your default photo viewer or web browser, you will get the following error:
Could not load image XYZ.webp Unrecognized image file format
To allow GDK applications such as Eye of Gnome (GNOME Image Viewer) to be able to view WebP images and animations, you need to install the webp-pixbuf-loader package.
WebP GDK Pixbuf Loader library is a third-party package and is not available for installation from the official repositories. You can install it from a PPA (Personal Package Archive) owned by Jonathan Yip.
Enable WebP Support to GNOME Image Viewer in Linux
On Ubuntu-based distributions, run the following command to add the PPA (Personal Package Archive) to your system, then update the APT package manager’s package cache to pick the list of the latest software within configured repositories in the system and install the package.
$ sudo add-apt-repository ppa:helkaluin/webp-pixbuf-loader $ sudo apt update $ sudo apt install webp-pixbuf-loader
On Fedora, users should run the following command to install it:
$ sudo dnf install webp-pixbuf-loader
On RHEL and other enterprise Linux distributions, enable the EPEL repository, then install it as follows:
$ sudo yum install epel-release $ sudo dnf install webp-pixbuf-loader
On Arch Linux, issue the following command:
$ sudo pacman -S webp-pixbuf-loader
To test if the package is working, open the default image viewer on your Ubuntu or Linux mint desktop and view a webp image with it.
After opening the image, you should be able to view it without any error as shown in the following screenshot.
View WebP Images Using gThumb Image Viewer in Linux
gThumb is an image viewer and browser for the GNOME environment that comes with Webp support. You can install it on your Linux distribution using your package manager as shown:
$ sudo apt install gthumb [On Debian, Ubuntu and Mint] $ sudo yum install gthumb [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a media-gfx/gthumb [On Gentoo Linux] $ sudo apk add gthumb [On Alpine Linux] $ sudo pacman -S gthumb [On Arch Linux] $ sudo zypper install gthumb [On OpenSUSE]
Once the package is installed, locate where the .webp image is, right-click on it, then go to Open with, and click Other application.
From the list of applications, search for gThumb and set it as the default application for opening and viewing Webp files/images. Then click OK, as highlighted in the following screenshot.
Now you should be able to open and view your WebP images.
Note that if you intend to convert your images from PNG and JPEG to webp format, you can use the dwebp or cwebp conversion tools as described below.
Convert WebP Images to PNG or JPEG Using dwebp Utility
To convert/decompress a Webp file into a PRN/JPEG image format on the command-line interface, you need to install the webp package as shown.
If the installation is successful, you should now have a utility called dwebp (which is part of libwebp) that you can use to convert .webp images to .png or .jpeg .
The following is an example where the -o flag specifies the output filename:
$ dwebp image.webp -o image.png $ dwebp image.webp -o image.jpeg
For more information, check the man page for dwebp:
Convert PNG or JPEG to WebP Using cwebp Utility
To convert a PNG/JPEG image file to a Webp file, use the cwebp utility. In this example, the -q flag is used to define the image quality:
$ cwebp -q 90 Selection_603.png -o Selection_603.webp
$ cwebp -q 60 -lossless image.png -o image_lossless.webp $ cwebp -q 80 image_with_alpha.png -o image_with_alpha.webp $ cwebp -sns 80 -f 50 -size 60000 image.png -o image.webp $ cwebp -o image.webp --image.png
For more information, check the man page for cwebp:
Convert WebP Images to PNG or JPEG Using XnConvert
XnConvert is a fast, powerful, and free multi-platform batch image converter that runs on Linux, Windows, and MacOS. It supports over 80 actions for managing images on your computer such as resizing, cropping, color adjustments, filtering, and much more.
It supports the most common picture and graphics formats such as JPEG, PNG, WebP, GIF, OpenEXR, camera RAW, HEIC, PDF, DNG, CR2, and much more.
To install it, download the .deb package from the project’s official website and install the XnConvert DEB package as shown:
$ sudo dpkg -i ~/Downloads/XnConvert-linux-x64.deb
After successfully installing it as shown in the previous screenshot, search for it in the system menu, and open it. Click on Add Files button to load an image file into the application for processing.
Next, click on the Output tab, under Format, and select the new format you wish to convert the current image format to, from the drop-down menu. And then click Convert.
In this example, we are converting a .png image file to a .webp format.
That’s all! Let us know your thoughts about this guide or webp image format via the comment section below.