- 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
- Wrap up
- 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 Convert PNG, JPEG to WebP in Ubuntu? ( Also WebP to PNG and JPEG )
- Installation
- Converting image to webp format
- Converting webp image to png and jpeg format
- Conclusion
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.
For those who get ffmpeg command not found, run the following command to install ffmpeg:
$ sudo apt install ffmpeg // Ubuntu, Debian $ sudo yum install ffmpeg // AlmaLinux, Fedora $ sudo pacman install ffmpeg // Arch Linux
Once the installation is complete, you can start with the conversion of the WebP image to JPG by running the following command:
$ ffmpeg -i input_webp_image.webp output.jpg
If you want to convert a WebP image to PNG, then change the extension to .png as shown below:
$ ffmpeg -i input_webp_image.webp output.png
But if you want to perform batch operations, then you can use the following command to convert all the WebP files that are available in current directory to png.
$ for FILE in *.webp; do ffmpeg -i "$FILE" -y "$.png"; done
Once you are done, you can verify the type of file using the file command.
Wrap up
That’s all for this short guide where you learn how to convert WebP image to JPG and PNG by using the dwebp and ffmpeg command.
So whenever you just need to convert a WebP image, run any of the following commands:
- Convert WebP to PNG
- $ dwebp input_webp_image.webp -o output.png
- $ ffmpeg -i input_webp_image.webp myfile.jpg
I hope you are able to convert the image, but if for some reason you are not able to accomplish it, then let us know in the comments section.
A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.
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 Convert PNG, JPEG to WebP in Ubuntu? ( Also WebP to PNG and JPEG )
Webp is an open-source image format in Linux which supports lossless and lossy compression for images on the web. One of the best practices to optimize the website performance is using compressed images. This article will cover how to use webp image format for creating compressed and quality images for the website.
Installation
The webp package is already available in the official ubuntu repositories. Run the command below to update the Ubuntu repository to the latest index and install webp package.
Also, you can install the webp package from Google’s repository as:
Extract the tar file and move to the extracted directory.
$ tar -xvzf libwebp-0.6.1-linux-x86-32.tar.gz
In the directory, you can see the precompiled binary files which are usable for various webp utilities such as:
anim_diff : This tool can be used to find the difference between animation images
anim_dump: This tool is usable to dump the difference between animation images
cwebp : This tool can be used for webp encoding
dwebp : This tool is used for webapp decoding
vwebp : This tool is used to view webp files
webpinfo : This tool is usable to view information about a webp image file
To find all the options provided by the webp utility tool, use the following command.
Now add the directory ~/libwebp-0.6.1-linux-x86-32/bin to the PATH environment variable in the ~/.bashrc file to run the webp utility tools without writing the absolute path.
Copy the following line at the end of the file.
export PATH=$PATH:~/libwebp-0.6.1-linux-x86-32/bin
Save the file and exit. Open a new terminal and use webp utility tools like other system commands.
Converting image to webp format
Using the cwebp tool, an image can be converted into webp format. Run the cwebp command with option -q to define the quality of image and -o to define the output file. In this example, I have used image file linux.png and linux.jpeg file to convert in webp format. You can choose your image name accordingly.
$ cwebp -q 60 linux.png -o linux.webp
$ cwebp -q 60 linux.jpeg -o linux1.webp
In the output, you can see that the size of the image has been comparatively decreased.
Run the following command to open the webp format images. In this example, I have used a previously converted linux.webp file.
Converting webp image to png and jpeg format
In the previous step, we converted jpeg and png images to webp using cwebp utility tool. Now we will use the dwebp tool to convert webp images into png and jpeg format.
Use the dwep command with the option -o to create png and jpeg image format from webp. In the example, image.webp is used for the conversion.
$ dwep image.webp -o image.png
$ dwep image.webp -o image.jpeg
It can be seen that the size of the image has been comparatively increased after decoding the webp image format.
In this way, we can convert png and jpeg format images to webp format and vice versa.
Conclusion
This article covered how to convert PNG, JPEG format to WebP in Ubuntu. Also, we learned how to convert WebP to PNG and JPEG.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.