March 24, 2019

Creating a Fancy 3D-Effect GIMP Plugin in Python

Your Fresh New BlobiPy Plugin

  • April 23, 2009
  • By Akkana Peck

Last time I wrote about the basics of a GIMP plug-in written in Python. But how do you figure out how to do anything that's actually useful? This article will show you.

Rounded 3D text

GIMP is great for adding text to images. You can pick a nice font and color, but it still looks flat

It looks a little better if you add a drop shadow,

but what if you want the letters to look more rounded and three-dimensional?

Here's a technique that gives a nice 3-D effect:

  1. Make a text layer in GIMP. The effect shows up best if you use a light color, like yellow, on a text layer that's on top of some other background like a pattern or photo.
  2. Use Layer->Transparency>Alpha to Selection to select just the text, nothing else.
  3. Invert the selection with Select->Invert
  4. Bring up Filters->Light and Shadow->Drop Shadow...
  5. Pick some appropriate values for offset and radius, and make the offsets negative: for my sample I used -3 and 7.
  6. Un-check the Allow resizing box, and click OK.
  7. Select->None to get rid of the selection outline.

It makes a nice 3-D effect.

But it's a lot of steps. Who wants to do that every time? Let's make a Python script to do it.


The first step is to pick a name for your script. I called this technique "blobify" when I wrote it in script-fu, since it makes the letters look blobby. I showed it in a talk on GIMP scripting, and when I got to the Python section of the talk, a clever audience member suggested that the Python version should be "blobi-PY". And so it should!

So the create a file called $HOME/.gimp-2.6/plug-ins/blobipy and make it executable, as in the previous article.

The blobipy script will need at least a register function and a function that will do the real work. Start with something like this:

#!/usr/bin/env python

from gimpfu import *

def python_blobify(img, layer, blur) :
# do the real work here

"Create a 3-D effect",
"Create a blobby 3-D effect using inverse drop-shadow",
"Akkana Peck",
"Akkana Peck",
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, "drawable", "Input layer", None),
(PF_SPINNER, "blur", "Blur amount",
7, (0, 50, 1))
menu="/Filters/Light and Shadow")


In the register function, I've specified three parameters for the script: a current image and a current layer -- "drawable" is just another name for "layer" -- and how much to blur. The python_blobify function takes three arguments corresponding to these three parameters.

The image and layer will be passed in automatically; the blur amount will be chosen by the user from a dialog that looks like Figure 4.


PF_SPINNER is a way of specifying a numeric amount: the default value is 7, but it can adjust from 0 to 50 by increments of 1 at a time.

Save the file and restart gimp. The script should show up in the Image window menus as Image->Filters->Light and Shadow->BlobyPy.

Most Popular LinuxPlanet Stories