Convert PNG images to WebP format with Imagemagick

Modern web is more about compression and one of it are images. There are many things which can be minified and compressed like CSS, JS, server side compression and even HTML of the page. Here I am going to show you how to convert PNG images to WebP format with Imagemagick while maintaining the same quality but reduced size.

Imagemagick is a library which can help us convert, edit raster and vector images. We will use the shorthand tool provided by Imagemagick called magick.

Open terminal in your favorite Linux distribution and install Imagemagick if not installed.

Manjaro/Arch

sudo pacman -S imagemagick
install-imagemagick-manjaro-in-terminal

Ubuntu

For Ubuntu and similar it would be:

sudo apt install imagemagick

Convert

The simplest form of usage is to use minimal options and get the job done.

magick src.png -quality 50 -define webp:lossless=true out.webp

Explanation:

magick = shorthand command to execute

src.png = the image which we want to convert

-quality = here we enter the quality of the output image, I like to keep it at 50

-define = this is for defining a few extra options, e.g lossless

out.webp = the final output webp file

Remember there are other combination of flags and options. It falls under the requirement and what one need from the final output.