WebP is a modern image format developed by Google that provides both lossless and lossy compression for images on the web, offering significantly smaller file sizes compared to traditional formats like JPEG and PNG - without a noticeable loss in visual quality. Google provides a set of command line tools for working with WebP images, including cwebp
for encoding and dwebp
for decoding. This tutorial shows how to install WebP utilities on Ubuntu 24.04.
Install WebP utilities
First, fetch the latest precompiled WebP archive download URL from the official documentation page:
WEBP_URL=$(curl -s https://developers.google.com/speed/webp/docs/precompiled | grep -Po 'https://storage.googleapis.com/downloads.*?linux-x86-64.tar.gz')
Download the archive:
wget -qO webp.tar.gz $WEBP_URL
Create a temporary directory to extract the archive contents:
mkdir webp-temp
tar xf webp.tar.gz --strip-components=1 -C webp-temp
Move the binary files into a dedicated directory under /opt
:
sudo mkdir /opt/webp
sudo mv webp-temp/bin/* /opt/webp
Add /opt/webp
to the PATH environment variable:
echo 'export PATH=$PATH:/opt/webp' | sudo tee -a /etc/profile.d/webp.sh
To apply the changes, you can either log out and log back in, or run the following command to activate them immediately:
source /etc/profile
Clean up the downloaded archive and temporary directory:
rm -rf webp.tar.gz webp-temp
Verify that the installation was successful by checking the installed versions:
cwebp -version
dwebp -version
Testing WebP utilities
To verify that the WebP tools are working correctly, start by downloading a sample image:
wget -qO test.png https://raw.githubusercontent.com/opencv/opencv/master/samples/data/sudoku.png
Next, use the cwebp
tool to convert the PNG to WebP format:
cwebp test.png -o test.webp
If the command runs successfully, a new file named test.webp
will be created in the same directory.
Uninstall WebP utilities
If you want to completely remove WebP utilities, delete the installation directory:
sudo rm -rf /opt/webp
Delete the webp.sh
file, which was used to set the environment variable:
sudo rm -rf /etc/profile.d/webp.sh
Leave a Comment
Cancel reply