Generate bitmap font: a little plug-in for The Gimp

I made this little plug-in for the Gimp because I needed to generate a fixed-width font bitmap (what I have called a Bitmap Font) to load and use in an application of mine. I then thought that maybe someone would like to learn how to make plug-ins for the Gimp with Python, as I did, so that's why I'm posting it here.

It turns out to be very simple. Your plug-ins need to be placed in your user's directory for the Gimp. In my case, that is ~/.gimp-2.6/plug-ins. When the program starts up, it will scan that folder, looking for any possible plug-ins there.

In my case, I decided I wanted to place the plug-in in the File menu, under Create:

File ... Create...

That is done with the register function at the end of the code, amongst other configuration settings for the window that shows up if you select my plug-in:


register(
    "sole_generate_bitmap_font",
    "Generate bitmap font",
    "Generate bitmap font",
    "Soledad Penades",
    "Soledad Penades",
    "2009",
    "<Image>/File/Create/_Generate Bitmap Font",
    "",
    [
        (PF_FONT, "Font", "Font", "04b03"),
        (PF_SPINNER, "Font_Size", "Size", 8, (0, 1000, 1)),
        (PF_RADIO, "orientation", "Orientation", "horizontal", 
            (("_horizontal", "horizontal"), ("_vertical", "vertical"))
        )
    ],
    [],
    sole_generate_bitmap_font)

Generate bitmap font

The plug-in, as it is, offers only few configuration options but if you want more, they can be added very easily. There's a but: the only thing I couldn't manage to do is to remove the "Input image" and "Input drawable" options (note they aren't specified in my code either, it seems they are added automatically).

Once you press 'OK', it will create a new document with the selected font. This is an example: Example bitmap font

Now, that isn't a fixed width font. When this texture is used for writing texts, it produces text that can be read but feels weird, because that font has not been designed to be used with fixed widths. Anyway, you get the idea. I'm still looking for a fixed width font that I like and find easy to read, so that's why I'm using this one for the example. It is the classic 04b_03 by 04.

You can take a look at the full source code here. Enjoy it!