Loading...
X

WebP image format: converting between formats, WebP lossless and lossy creation and verification in Linux

Contents

  1. WebP image format: how to create WebP lossless and lossy and convert to JPG
  2. Why is WebP better
  3. Utility for converting to WebP format and from WebP format to other formats
  4. How to convert an image to WebP format
  5. How to convert an image from WebP format to JPG and any other format
  6. How to convert to WebP without loss of quality – WebP lossless
  7. How to check if WebP is lossless or lossy
  8. An easy way to convert WebP without installing programs

1. WebP image format: how to create WebP lossless and lossy and convert to JPG

This article is dedicated to the WebP image format: we will consider how to convert a photo from JPG (or any other format) to WebP; how to vice versa convert the WebP format to JPG and other popular image formats; how to create WebP lossless and lossy; and also how to check whether WebP is lossless and lossy.

2. Why is WebP better

You may have noticed that some websites have switched to WebP as the main format for photos and images. What are the advantages of the WebP format?

WebP images:

1) take up less space than JPG and PNG with the same quality

2) support both lossy and lossless compression

3) support transparency (alpha channel)

4) are widely supported by both user applications on devices (photo viewing programs on computers and phones) and online (all web browsers support WebP, WordPress and many sites support WebP)

In terms of its technical capabilities (for example, compression level and color depth), the WebP format is inferior to more advanced formats such as HEIC and AVIF. But if we talk about prevalence and support by user and server software, then WebP is probably the best in terms of the ratio of “technical characteristics – software support”.

See also: What is a WebP file and how is it better than other formats

3. Utility for converting to WebP format and from WebP format to other formats

In this tutorial, we will use ImageMagick, if you do not have this package installed yet, see the section “How to install ImageMagick on Linux”.

See also: ImageMagick guide: installing, using, and troubleshooting

4. How to convert an image to WebP format

To save any photo to WebP format, use a command like this:

magick ORIGINAL_FILE NEW_FILE.webp

For example, I want to convert the file 20240111_124943.jpg to WebP format, then the command will be as follows:

magick 20240111_124943.jpg 20240111_124943.webp

Note: the name of the new file can be anything – the main thing is to specify the file extension correctly.

Note 2: You can convert to WebP format not only from JPG, but from any other image formats.

Let's compare the JPG and WebP formats visually. You can compare the image quality using the following photos. When you click on the pictures, the original image files will be opened.

The first image is the original JPG file (size 4.3 MB):

The second image is the WebP file (size 3.1 MB):

5. How to convert an image from WebP format to JPG and any other format

To convert photos in WebP format, use the following command:

magick ORIGINAL_FILE.webp NEW_FILE

Please note that the NEW_FILE format will match the specified extension. For example, to convert to JPG, the command should look like this:

magick ORIGINAL_FILE.webp NEW_FILE.jpg

For example:

magick 20240111_124943.webp beach.jpg

And to convert to AVIF format, the command should look like this:

magick ORIGINAL_FILE.webp NEW_FILE.avif

For example:

magick 20240111_124943.webp beach.avif

6. How to convert to WebP without loss of quality – WebP lossless

To convert to WebP lossless, you need to use a command like this:

magick ORIGINAL_FILE -define webp:lossless=true NEW_FILE.webp

For example:

magick test2.png -define webp:lossless=true test2.webp

Please note that the JPG format is a lossy format and, usually, it does not make much sense to save JPG files in WebP lossless – yes, thanks to this, the original quality of the JPG file will be preserved, but the file size will increase significantly.

Another lossless format is PNG – when converting images from PNG to WebP, you can choose whether you want to save in WebP lossless (without loss of quality) or in WebP lossy (to reduce the occupied space).

Let's compare PNG and WebP formats visually. You can compare the image quality using the following photos.

PNG source file (file size 2.2 megabytes):

WebP lossless (size 1.6 megabytes)

WebP lossy (97 kilobytes – note the phenomenal level of compression):

See also: WebP Encoding Options

7. How to check if WebP is lossless or lossy

Let's look at how to check WebP for lossless.

For this we will need the webpinfo utility.

To install webpinfo on Debian, Ubuntu, Linux Mint, Kali Linux and their derivatives, run the command:

sudo apt install webp

To install webpinfo on Arch Linux, Manjaro, BlackArch and their derivatives, run the command:

sudo pacman -S libwebp

Now to check if WebP is lossy or not, run the command:

webpinfo FILE.webp

For example:

webpinfo test2_lossless.webp

Example output for WebP lossless:

File: test2_lossless.webp
RIFF HEADER:
  File size: 1714518
Chunk VP8L at offset     12, length 1714506
  Width: 1705
  Height: 1279
  Alpha: 0
  Animation: 0
  Format: Lossless (2)
No error detected.

Note the word “Lossless” in the “Format” line.

Let's check another file:

webpinfo test2_lossy.webp

Example output for WebP Lossy:

File: test2_lossy.webp
RIFF HEADER:
  File size:  99382
Chunk VP8  at offset     12, length  99370
  Width: 1705
  Height: 1279
  Alpha: 0
  Animation: 0
  Format: Lossy (1)
No error detected.

Note the word “Lossy” in the “Format” line.

8. An easy way to convert WebP without installing programs

If you want to convert photos to WebP format or you need to convert an image from WebP format or you want to check whether a WebP file is lossy or lossless, but you do not want to install programs and deal with the command line, then you can use online services to perform all these functions:

Immediately after processing and sending you the results, your files are deleted from the server (both the original file and the one obtained as a result of conversion).

Using the services is extremely simple – you just need to specify the file you want to process.

Additional options are also available for those who need more – you can convert to WebP lossless or choose from a list of popular formats if you need to convert a WebP file.


Leave Your Observation

Your email address will not be published. Required fields are marked *