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.
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.
sudo apt install webp
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
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