Skip to content

Title cards for videos with Common Lisp

Xach posted recently about Fighting blog spam with Common Lisp as a short example of using lisp to solve everyday programming problems.  Here’s one I made last weekend.

The Problem:

My wife belly dances, and we frequently do some light video editing before posting things to youtube.  One of the annoying chores is making title cards, usually white text on a black background that we put at the beginning and end of each video to state time, place, etc, and then fade in/out.  An example:

Text should be large enough to fill the screen, centered, and all the same size.  For awhile I made these in Gimp, then made them in HTML and took screenshots, and finally said screw it and wrote a small helper program.  I don’t know how to use Gimp effectively, and jiggling font sizes in HTML is a pain.  I’m sure there are better solutions, but it was faster (and more fun) for me to write some lisp.

The Solution:

To make title cards, I wrote a little program called “Titler”.

Like Xach’s project, I started with (quickproject:make-project "~/src/lisp/titler/" :depends-on '(vecto iterate))

From there I banged away at it for a little while, found some .ttf files on my system and got the basic generation done using vecto’s string drawing functions. The only tricky bit was to determine the optimal font size. Vecto provides a string-bounding-box function that will give you pixel dimensions for a given string at a given font size. I made a function that uses newton’s method to iteratively try different font size values until we get one that fits on the title card and takes up more than 75% of the width. I’m almost positive there are corner cases where my implementation won’t converge on a solution, but it works pretty well for now.

For the next video I can make easy titles:

(make-title "

May 26, 2011
Sun Center
Gainesville, FL" 640 480)

Code is at, and you can see the results (and my wife fire dancing) at


  1. Zach Beane wrote: has a scheme for determining exactly what size font to use to fit a particular pixel width. Hope you find it useful.

    I had to use something very similar to get drawn properly.

    Sunday, June 5, 2011 at 8:14 pm | Permalink
  2. Tom Emerson wrote:

    Another Lisper who is the husband of a belly dancer… small world. :-)

    Monday, June 6, 2011 at 1:31 pm | Permalink
  3. ryan wrote:

    @Zach Thanks! That’s a much better way of calculating font size.

    Monday, June 6, 2011 at 1:44 pm | Permalink