Record a GIF with Linux

Max Rosin

I found a cool tool called Peek to record a GIF with linux. Unfortunately it does not work well with i3.

So I ended up using byzanz-record instead. My only issue with byzanz is that it requires you to pass x and y coordinates when you want to record a selection of your screen and usually I do not like to count pixels before every recording...

Luckily someone wrote xrectsel, a simple tool to get the geometry of a selected screen region. By combining xrectsel and byzanz it is possible to record a nice GIF with i3 and probably all other window managers:

byzanz-record                                        \
  --cursor                                           \
  --verbose                                          \
  --delay=2                                          \
  --duration=10                                      \
  $(xrectsel "--x=%x --y=%y --width=%w --height=%h") \
  /tmp/recording.gif

To make my life easier I put it in a small shell script called gif.sh:

#!/usr/bin/env sh

[ $# -lt 2 ] && \
  echo 'You have to pass a duration in seconds and a filename: "gif.sh 10 /tmp/record.gif"' && \
  exit 1

byzanz-record                                        \
  --cursor                                           \
  --verbose                                          \
  --delay=2                                          \
  --duration=${1}                                    \
  $(xrectsel "--x=%x --y=%y --width=%w --height=%h") \
  "${2}"
Example usage of the script

Max Rosin

I am a Systems Engineer from Germany. In my personal time I like to tinker with all kinds of technologies, some of it is available here at my blog. In my professional life I work a lot with Kubernetes and monitoring systems. Occasionally I give workshops about Kubernetes and conference talks about my work.
If you want to talk about one of my posts, feel free to reach out via Twitter.