How to install the libwebp library

What is libwebp?

Libwebp is an open source software library developed by Google to encode and decode images in the WebP format.

WebP, also created by Google, is an image format that offers high quality with smaller file sizes than traditional formats such as JPEG and PNG.

This means that WebP images load faster, which can improve performance and user experience on websites and applications.

libwebp provides an easy way to integrate WebP functionality into your own programs.

Some of libwebp’s features include:

  • WebP image encoding and decoding.
  • Support for lossy and lossless images.
  • Support for transparency.
  • Precise control over image quality.
  • Easy-to-use APIs.

Installation

Linux

Arch Linux

sudo pacman -S \
libwebp

Fedora

sudo dnf install \
libwebp

Ubuntu

sudo apt install \
libwebp

macOS

Homebrew

brew install \
webp

Pre-compiled utilities

Google provides pre-compiled utilities for the following operating systems:

  • Microsoft Windows (x64).
  • Linux (aarch64).
  • Linux (x86-64).
  • macOS (arm64).
  • macOS (x86-64).

To download the utility go to:

After downloading, unzip the downloaded file into a directory where it will not be removed.

Then add the bin folder to the operating system’s PATH.

Linux

Edit the .bashrc file and add the path to the bin folder:

export PATH="path/folder-name/bin:$PATH"

Some Linux distributions already have the $HOME/.local/bin and $HOME/bin folders mapped in the PATH variable.

In this case, simply copy the binaries from the bin folder to one of the operating system’s bin folders.

If you need to map these directories in the operating system’s PATH variable, you can use the following commands:

echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc

Or

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

After adding it, you need to run it:

source ~/.bashrc

macOS

Add the path to the bin folder in the .bash_profile file:

export PATH="$PATH:path/folder-name/bin"

Or add a file with the path to the paths.d directory:

sudo -s 'echo "path/folder-name/bin" > /etc/paths.d/libwebp'

Microsoft Windows

Open the Environment Variables application.

Select the Path variable and click the Edit… button:

Selecione a variável Path e clique no botão Editar...:

Aplicativo Variáveis de Ambiente.
Aplicativo Variáveis de Ambiente.

Click on new and add the path to the bin folder:

Aplicativo Editar a Variável de Ambiente.
Aplicativo Editar a Variável de Ambiente.