How to Convert WebP to PNG in Linux

WebP is a modern image format created by Google. It was made specially for the Web, providing a high compression ratio without affecting the image quality. On Windows, any image viewer like IrfanView can open WebP images and save them as JPG/PNG. On Linux however, it might be hard to edit or convert a WebP image, because traditional image editing tools like GIMP do not support WebP yet. Here is how to convert a WebP image to the PNG format and vice versa.

GIMP Error Message Webp

There are two methods you can use to get a PNG image from an existing WebP image. You can use either libwebp or ffmpeg packages which provide tools for our tasks.

Convert WebP to PNG

Depending on your distro, libwebp may be installed out-of-the-box, or not. For example, in Arch Linux package dependencies are not strict, so libwebp doesn't get installed when you install the GUI. You should install it manually by running the command as root:

# pacman -S libwebp

On a Debian-based distro like Linux Mint, issue the command:

# apt install webp

The package provides the following tools:

  • cwebp - a WebP encoder tool.
  • dwebp - a WebP decoder tool.
  • vwebp - a WebP viewer app.
  • wepmux - a WebP muxing tool.
  • gif2webp - a tool for converting GIF images to WebP.

To convert a WebP image to PNG in Linux, do the following.

  1. Open your favorite terminal app.
  2. Type the following command:
    dwebp file.webp -o file.png
  3. The output file will be file.png in the PNG format.Linux Webp To Png

Note: Unfortunately, dwebp only converts WebP to PNG, but not to JPG. So, if you need to get a JPEG image from your WebP file, you need to convert it to PNG first, and then convert the PNG image to JPG using a tool like GIMP or convert it using ImageMagicK.

Convert WebP to PNG with ffmpeg

If you can't get libwebp installed, you can go with ffmpeg. Unlike libwebp, ffmpeg is widely used and comes preinstalled in many distros. Do it as follows:

  1. Open your favorite terminal app.
  2. Type the following command:
    ffmpeg -i file.webp file.png

Linux Webp To Png FfmpegKeep in mind that ffmpeg produces bigger files than the WebP encoder. You might need to adjust its options and optimize the output file.

Convert PNG files to WebP

The opposite conversion might also be useful. In a number of situations, WebP provides a better compression ratio than PNG. To convert a PNG file to WebP, execute the following command:

cwebp file.png -o file.webp

The default quality for WebP is set to 75. You can increase or reduce it by specifying the -q argument for the encoder, as follows.

cwebp -q 80 file.png -o file.webp

That's it.

5 thoughts on “How to Convert WebP to PNG in Linux

  1. Phil

    Thanks for sharing! I will try in Linux when I get a chance

    Reply
    1. Sergey Tkachenko Post author

      You are most welcome.

      Reply
  2. Jean

    I’ve installed the webp package on Ubuntu and it works great.
    Thanks for these instructions!

    Reply
  3. serii

    How to convert a few files?

    Reply
    1. Sergey Tkachenko Post author

      ———–
      1. Create a *.sh file:

      #!/bin/bash
      for a in ./*.webp; do
        old=$IFS
        IFS="\n"
        ffmpeg -i "$a" "${a[@]/%webp/png}"
        IFS=$old
      done

      ————
      2. Then make it executable: chmod +x yourfile.sh
      ———–
      3. Run it in the directory with your files.

      Reply

Leave a Reply

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