Home Linux Commandline Tools How to Convert WebP Images to PNG and JPEG in Linux

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.

$ ls -l image.webp
Sample WebP Image File
Sample 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
Convert WebP to PNG in Linux
Convert WebP to PNG in Linux

In terms of size comparison, the PNG file should be bigger:

$ ls -l final.png
Check PNG Image Size in Linux
Check PNG Image Size in Linux

Converting WebP Image to JPEG in Linux

To convert our raw WebP image to JPEG image, implement:

$ dwebp image.webp -o final.jpeg
Convert WebP to JPEG in Linux
Convert WebP to JPEG in Linux

The JPEG file should also be bigger that the original WebP file.

$ ls -l final.jpeg 
Check JPEG Image Size in Linux
Check JPEG Image Size in Linux

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.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

2 thoughts on “How to Convert WebP Images to PNG and JPEG in Linux”

  1. Thanks for this, worked fine for converting to PNG.

    However, dwebp version 0.6.1 on Ubuntu Linux 20.04.4 LTS: did not actually convert to JPG format. It produces the output file with the correct extension, but the -o option produces a PNG file format.

    Other formats such as BMP and tiff can be explicitly specified as an option before the -o (-tiff, -BMP, etc…)


Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.