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.
Lets first install the software we need. We need above mentioned screen casting software, and we also need imagemagick and mplayer. So lets 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.
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 of witch 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 resource 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:
Using Byzanz to make GIF
Byzanz is another software which can greatly simplify the creation of the GIFs. First, off 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
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
byzanz-record [OPTION...] record your current desktop session
-?, --help Show help options
--help-all Show all help options
--help-gtk Show GTK+ 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
Using peek to make GIF
Peek is great piece of software that enables you to quickly record GIFs by selecting and recording piece of screen. To get peek
To get dependancies
sudo apt install libsdl1.2debian ffmpeg
Installing the package
sudo dpkg -i peek-0.7.2-Linux.deb
And start the peek
It will give you frame like this
You can easily use this frame to get piece of the screen and record GIF there. For example I will Peek into terminal again.
There we have three ways to make animated GIFs in Ubuntu. First method, using imagemagick, is also useful if you have video from 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.
You might also like
Filed Under : OPEN SOURCE TOOLS