Create GIF on Linux OS - A Step by Step Guide

Sohail
Sohail

Table of Contents

Creating GIF on Linux can seem intimidating, but with the right tools and instructions, it’s easy! In this guide, we will show you how to create customized GIFs using Linux operating systems in just a few simple steps.

Pre-requisites

How to create GIF in Linux

If you already have a sequence of images, you can avoid using FFmpeg and can either use Gimp or command-line tool ImagicMagick to create a .gif out of the images. If you do not have images, then you can create a sequence of images from a video using FFmpeg and use them to create .gif.

Install GIMP

sudo apt install gimp

The first step for creating GIFs on Linux is to install the popular open source image editing software, GIMP. This will allow you to create a wide variety of visual effects, such as adding text and altering color palettes. Once you have installed GIMP, you can begin creating your GIF.

Install FFMpeg

As mentioned above if you do not already have images, you can use FFmpeg to create a sequence of images from a video.

sudo apt install ffmpeg

Convert a Video File to Image Files

Once you have FFmpeg installed, the next step is to convert your video file into several image files. The following command can be used to transform videos into separate frames that can then be used in GIF creation. You can also use command line tools like convert to quickly perform this transformation without much effort. Once completed, you will have all the necessary images for creating your GIF!

ffmpeg -i your_video.mp4 -vf "select=eq(pict_type\,PICT_TYPE_I)" -vsync vfr thumbnail%04d.png

Install ImageMagick

Once we have our images, we can either use command-line tool ImageMagick or GIMP to convert these images into a nice gif. Let’s first see how we can do it using ImageMagick.

sudo apt install imagemagick

Convert the image sequence using ImageMagick

Open terminal and cd into the directory where you created images from the video. Now use the following command to make the gif. The procedure may take sometime depending on the number and quality of the images and the length of the gif. So sit back and relax.

convert -delay 5 -loop 0 thumbnail*.png animation.gif

Don’t worry. If you run into the error, make the following changes to the imagemagick config –

sudo nano /etc/ImageMagick-6/policy.xml

Now find the line –

<policy domain="resource" name="disk" value="1GiB"/>

And change the value from 1GiB to 8GiB.

<policy domain="resource" name="disk" value="8GiB"/>

And re-run the convert command and it should work this time.

Convert the image sequence using GIMP

Open the Image Sequence in GIMP

Import images to create GIF
Import images to create GIF

You can open the image sequence in GIMP. Start by clicking File > Open and then select the folder containing all your images. All the images will automatically be opened in a single window. You can adjust any of the settings for the individual frames if needed, but for most cases you won’t need to make any adjustments. When everything looks satisfactory, click on “Save as Animation” to create your GIF.

Trim, Resize, and/or Speed up Your GIF Speed

After saving the GIF, you may find that some frames or parts of the GIF need to be trimmed. You can click on any frame and then click “Delete Frame” in the top menu to remove it from your animation. If you need to resize an individual frame of the GIF, simply select “Scale Image” under the Image menu. And finally, if you need to speed up or slow down your animation, use GIMP’s “Frames Delay” setting under the Filters menu. Adjust this setting for each of your frames until you are satisfied with the speeds of your GIF.

Add Text, Filters, etc., to Enhance Your GIFs Visual Appeal

GIMP also provides some powerful tools to help you add text, graphics, and filters to your GIFs to make them more attractive. To add text, select “Text” from the toolbox and click on the area of the image where you would like the text to appear. Once you have typed in your desired text and changed its font, size, color, etc., use the Transparency setting to adjust its opacity. You can also choose from a variety of filter effects such as sharpening, blurring, posterizing, and solarization. These tools will help you make an eye-catching animation clip in no time!

Creating a GIF from a screen recording

You must have seen animated GIFs of a recorded screen. We can create gif from a screen recording using the byzanz. It’s a command-line tool that will record the screen and create the gif.

byzanz-record --duration=15 --x=0 --y=0 --width=800 --height=600 animated.gif

The above command will record the screen for 10 seconds and convert it into gif. You can adjust the parameters such as the duration of the gif, x and y coordinates, width and height of the screen.

Conclusion

And that’s pretty much it for how to create GIFs on Linux. Depending on your particular situation, you might not need all the above tools. Just use the ones you need and create your desired gif. If you run into issues, let me know in the comment section below.

Linux TutorialsUncategorizedhow-to