Creating an Emacs Demo Gif
For the release of my new Emacs package toodoo, I wanted to do something I have never done before - prepare a gif demo for the main README. Suprisingly, this was quite easy, as I document below.
Firstly, you could simply use a screencapture tool. But this a heavyweight solution, necessarily. Enter gif-screencast to the rescue. The way it works is by taking a screenshot everytime you have keypress.
I used the following configuration:
(require 'gif-screencast) (setq gif-screencast-program "convert" gif-screencast-args '("x:root")) (global-set-key (kbd "<f9>") 'gif-screencast-start-or-stop)
Here, I am using convert
from Image Magick to take the screenshot. The arg x:root
asks it take the full screen image. That is, run Emacs in full-screen mode when you want to take the shot.
Now, you can use F9
to start and stop. You also need gifsicle
installed as the processing program. This process creates a couple of gifs in your home directory.
Now that the basic stuff is in place, we need a way to display keypresses in the gif so that viewers know what we are doing. The option recommended by gif-screencast
is KeyCast which is another emacs only solution: keys are displayed in the modeline.
I couldn't use this for 2 reasons:
- I don't have a modeline - for style reasons. Still, I enabled it back to see how KeyCast would work.
- It doesn't seem to register keypresses in Transients (the magit library used to create nice user-friendly pop-ups).
Enter ScreenKey.
So, now we get nice large band of keypresses. We are done, right? No - we are not.
The problem was that the large band ended by covering the very transients I was trying to show-off in the demo! So, the modified command needed was:
./screenkey -g $(slop -n -f '%g')
which allows you to choose a section of the screen to actually use as the base. Note: the keys are still added to a band at the bottom of this selected region. This needs another tool: slop.
Now, we are done right? No, we are not.
Since we are using F9
, towards the end of the capture, we get the keypress recorded into the gif. This can be confusing to the viewer, since it is not actually part of the demo. So, we need to edit the gif to remove the spurios stuff.
gifsicle
comes to the rescue.
gifsicle --info <name of gif> gifsicle <src> '#0-n' > <dest>
Using --info
, we get the actual sequence of images used to make the gif, with timestamps and durations. The second command can be used to crop the gif to a sequence of the existing images, here 0 to n. So, simply using n-1 as the number here, we can remove the last image in the gif.
That's it. You can see the gif I created running in the toodoo readme.