Best Tools to Make Animated GIF in Linux Systems

Posted on : October 21, 2016 , Last Updated on : June 20, 2017 By
| 4 Replies More

Animated GIF images have become an art of its own, with funny scenes and memes flooding the internet. Animated GIFs are also useful to us geeks, for example for showing interactive terminal output. When there is not enough content to warrant entire video but you still need moving picture, animated GIF is what you need. So today we will show three ways you can create GIFs using open source Linux software.

1) Using gtk-recordmydesktop

Lets first install the software we need. We need above mentioned screencasting software,  and we also need imagemagick and mplayer. So let's install them.

sudo apt-get install imagemagick mplayer gtk-recordmydesktop

Next we use recordmyDesktop software to record terminal window while we execute some command. We will keep it simple so we will just ping google. When that is recorded, and file is saved in ~/Videos/mygif.ogv we move to next step. First cd into videos directory.

cd Videos/

mkdir img_mygif

Then we need to dissemble the video to frames

miki@miki-X550JK:~/Videos$ mplayer -ao null mygif.ogv -vo jpeg:outdir=/home/miki/Videos/img_mygif

It will play video and start the process, at the end we will have images in the ~/Videos/img_mygif directory. You can enter that directory and delete some of the images on start and the end in order to make GIF shorter.

To create actual GIF, we need to use imagemagick to fuse images back together in GIF format. It is very resourced intensive task, it can throw down to knees even most powerful ones of machines, so we will use options to limit usage of resources, which will in turn make the process take more time. But at least you wont end up with completely unresponsive system.  The options for limiting are -limit memory 1 -limit map 1

convert -limit memory 1 -limit map 1 /home/miki/Videos/img_mygif/* final.gif

In order to make the gif smaller we can optimize it

convert -limit memory 1 -limit map 1 final.gif -fuzz 10% -layers Optimize final_optimzed.gif

And here is the final GIF:

gtk recordmydesktop animated gif

2) Using Byzanz to make GIF

Byzanz is another software which can greatly simplify the creation of the GIFs. First, of course we need to install Byzanz.

sudo apt install byzanz

We can right away start by making a GIF

byzanz-record --duration=5 --x=500 --width=250 --height=100 newgif.gif

Byzanz animated gif

The most challenging part here is actually fitting the right area of the screen to capture. The options width and height need to be tested several times before you get the right alignment. Here are the options and the syntax of byzanz-record command:

miki@miki-X550JK:~$ byzanz-record --help
Usage:
byzanz-record [OPTION...] record your current desktop session

Help Options:
-?, --help Show help options
--help-all Show all help options
--help-gtk Show GTK+ Options

Application Options:
-d, --duration=SECS Duration of animation (default: 10 seconds)
-e, --exec=COMMAND Command to execute and time
--delay=SECS Delay before start (default: 1 second)
-c, --cursor Record mouse cursor
-a, --audio Record audio
-x, --x=PIXEL X coordinate of rectangle to record
-y, --y=PIXEL Y coordinate of rectangle to record
-w, --width=PIXEL Width of recording rectangle
-h, --height=PIXEL Height of recording rectangle
-v, --verbose Be verbose
--display=DISPLAY X display to use

3) Using peek to make GIF

Peek is a great piece of software that enables you to quickly record GIFs by selecting and recording a piece of screen. To get peek

wget https://github.com/phw/peek/releases/download/v0.7.2/peek-0.7.2-Linux.deb

To get dependencies

sudo apt install libsdl1.2debian ffmpeg

Installing the package

sudo dpkg -i peek-0.7.2-Linux.deb

And start the peek

peek

It will give you frame like this

peek Frame

You can easily use this frame to get a piece of the screen and record GIF there. For example, I will Peek into terminal again.

Peek animated gif

4) Using Gifine to make animated GIF

Gifine is a free GTK based application tool that can be used to record your desktop screen and create animated gifs or video.

Before starting, you will need to install FFmpeg to your system. By default, FFmpeg is not available in Ubuntu default repository. So you will need to add PPA for FFmpeg. You can do this with the following command:

sudo add-apt-repository ppa:mc3man/trusty-media

Next, update your system with the following command:

sudo apt-get update -y

Finally, install FFmpeg with the following command:

sudo apt-get install ffmpeg -y

Next, you will also need to install other dependencies required by Gifine. You can install all of them with the following command:

sudo apt-get install gcc make build-essential graphicsmagick gifsicle luarocks -y

Next, you will need to download and compile XrectSel to your system. It's basically an application that tells you the geometry of a rectangular screen region which you have selected by dragging the mouse/pointer. You can download it with the following command:

wget https://github.com/lolilolicon/xrectsel/archive/master.zip

Once the download is finished, extract the downloaded file with the following command:

unzip master.zip

Next, change the directory to the extracted directory and install XrectSel with the following command:

cd xrectsel-master
sudo ./bootstrap
sudo ./configure --prefix /usr
sudo make
sudo make DESTDIR="$directory" install

Finally, install Gifine with the following command:

sudo luarocks install --server=http://luarocks.org/dev gifine

Once Gifine is installed, you can launch it with the following command:

gifine

You should see the Gifine application UI in the following image:

Next, click on the Record rectangle button, then select a rectangular area on your screen which you want to record. Recording is now begins and you should see the following image:

Once you are done with the recording, click on the Stop recording button. You should see the following image:

Next, click on the Save GIF or Save MP4 button to save the recording as a GIF or a video.

Conclusion

There we have three ways to make animated GIFs in Ubuntu. The first method, using imagemagick, is also useful if you have video from the internet, ie, not made by yourself. Second and third method rely on you making the screencast on your computer. You can pick methods based on your needs and preference, and generally, all three can get you the same result. This was all for today's article, thank you for reading.

Filed Under : OPEN SOURCE TOOLS

Tagged With : ,

Free Linux Ebook to Download

Comments (4)

Trackback URL | Comments RSS Feed

  1. Song says:

    Will imagemagick work in Ubuntu 16.04?

  2. James Van Damme says:

    I tried to make a gif out of several pictures that I shot in rapid succession. I used Gimp, which makes it easier to crop them to the same area and then make the animation. But for some reason the output was low color depth, which looked terrible on a photo.

    • Mihajlo Milenovic says:

      I had similar problems now and then, but I found out that Peek is most trouble free of above. There is also java based ScreenStudio, but haven't been able to make it work.

      I dont have solution for that problem other than switching software and trying what works best.

Leave a Reply

All comments are subject to moderation.