webp to gif images in linux

How to Convert Webp to Gif in Linux

Webp is a popular image format that is highly optimized for delivery on websites and web applications. Since it is much smaller in size than traditional image files such as PNG, JPG & Gifs they can be loaded faster, and consume less data. But sometimes you may need to convert webp to gif in Linux. You can easily do this using ImageMagick library. In this article, we will learn how to convert webp to gif in Linux.


How to Convert Webp to Gif in Linux

Here are the steps to convert webp to gif in Linux. Here are the steps to install ImageMagick.

1. Install ImageMagick

$ sudo apt update
$ sudo apt install imagemagick

Alternatively, you can compile ImageMagick from source. Download ImageMagick tar.gz file from here.

Extract the tarball you have downloaded.

$ tar -xvf ImageMagick.tar.gz
$ cd ImageMagick-7.0.10-11/

Run the following command to compile ImageMagick.

$ ./configure
$ make

Run the following command to install ImageMagick.

$ sudo make install

Run the following command to configure dynamic run-time bindings.

$ sudo ldconfig /usr/local/lib


2. Convert Webp to Gif

ImageMagick package consists of several image editing tools. Out of them, you can use convert and mogrify command to convert webp to gif files. Let us say you have test.webp image. Here is the command to convert test.webp image to test.gif. Here is the syntax of convert command.

$ convert [options] /path/to/webp /path/to/gif

In the above command, you need to specify the source path to web image first, followed by target path to gif image.

Here is an example to convert /home/ubuntu/test.webp to /home/ubuntu/test.gif.

$ sudo convert /home/ubuntu/test.webp /home/ubuntu/test.gif

The above command convert can only convert one file at a time. If you want to convert more than one webp images to gif, then you need to use mogrify command. Here is the syntax to convert .webp images to gif files using mogrify command.

$ mogrify [options] /path/to/source/file

Here is the command to convert all .webp images in /home/ubuntu folder to gif files.

$ sudo mogrify -format gif /home/ubuntu/*.webp

With mogrify command, if you mention only the source path of webp files it will replace them with converted gif files.

If you don’t want to overwrite the existing files but create the converted files at a different location, then specify the destination path using -path option.

$ mogrify -format pdf -path /home/ubuntu /home/ubuntu/*.jpg

If the above mogrify command doesn’t work for you, then depending on the platform and type of ImageMagick installation, you may need to add keyword magick before your mogrify command.

$ magick mogrify -format pdf /home/ubuntu/*.jpg
$ magick mogrify -format pdf -path /home/ubuntu /home/ubuntu/*.jpg

In this article, we have learnt how to convert webp to gif images in Linux. You can run them as standalone commands or as a part of a bigger shell script in Linux. If you want to convert single webp file to gif, you can use convert or mogrify commands. If you want to convert multiple webp images to gif files, you need to use mogrify, or call convert command while running a loop through your webp files.

Also read:

How to Convert Images to Webp in Linux
How to Convert Images to Webp in Python
How to Check If User Has Sudo Access
How to Combine JSON Files to CSV Files
How to Convert JSON to CSV in Python

Leave a Reply

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