Convert PNG and JPEG to WebP in Ubuntu

PNG (Portable Network Graphics) and JPEG (Joint Photographic Experts Group) are both image file formats. While, WebP – an image file format developed by Google can be used to deliver web content faster. It is smaller in size as compared to that of PNGs and JPEGs. In this article, we cover how to convert PNG and JPEG images file to WebP images in Ubuntu.

We utilize command-line utility – cwebp. With the help of cwebp, we can compress PNG and JPEG images to WebP images. But, to have it we need to install webp package.

Installation steps required for webp are discussed next.

Note: Following operations require you to have superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.

Install webp in Ubuntu

The package webp is available through standard Ubuntu repository. So, we don’t have to download packages from the internet. Just update the repository. This we do to make sure we get to have the latest version of the package. Hence, open a terminal and issue the following –

sudo apt update

Thereafter, to install webp –

sudo apt install webp

Convert PNG to WebP in Ubuntu

So, we first start with – PNG to WebP. Use the following syntax to convert PNG to WebP

cwebp -q <float_value> <input.png> -o <output.webp>

where, -q is used to set the output quality.

<float_value> for Quality output, ranging between 0 and 100. Here, 0 being very poor and 100 for excellent.

<input.png> the input file.

Lastly, <output.webp> name of desired WebP file.

For instance, if we want Quality to be 60 of input PNG file – test.png. And, the desired output file – converted.webp. We can use the following command for such values –

cwebp -q 60 test.png -o converted.webp

Convert JPEG to WebP in Ubuntu

Similarly, if we want to convert JPEG to WebP then –

cwebp -q <float_value> <input.jpeg> -o <output.webp>

Just that, here we provide JPEG file as input instead of PNG file (as was the case in previous section). Rest all of it remains the same.

In conclusion, we have covered how to convert PNG and JPEG to WebP in Ubuntu here. To view WebP images in Ubuntu.

Similar Posts