Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to convert an image to WebP

Sarvech Qadir

WebP is an image format employing both lossy and lossless compression that was developed by Google. There are many ways to convert an image to WebP.

Using Sketch

A user may use the Sketch tool to convert any image to WebP directly. Just follow these steps:

  1. Select the resource to be converted to WebP.
  2. Open the export panel and choose the format option as WEBP.
  3. Lastly, click Export Bitmap. You may be prompted to specify the image’s quality to be exported on a scale of 0-100.

Using the terminal

We can convert image formats, like jpeg and png, to WebP format using a series of commands. These commands are explained in the following steps:

Step 1

Open a terminal in the directory where the image you want to convert is present.

Step 2

Get cwebp, dwebp, and the WebP Libraries. In Linux, we can use the following command:

> wget

This creates a .tar file at our location.

Step 3

Extract the .tar file:

> tar -xzvf libwebp-1.1.0-linux-x86-64.tar.gz

This will create another directory, libwebp-1.1.0-linux-x86-64.

Step 4

The directory created above contains many folders, but we are only going to work with the bin folder. Therefore, type the following command in the terminal:

> ./libwebp-1.1.0-linux-x86-64/bin/cwebp/ -q 80 img.png img.webp

// The first parameter is the cwebp directory.
// The second and third parameters refer to the quality. 
// The fourth parameter is the name of our source image.
// The fifth parameter is what we want to name our converted image.




Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring