Friday, March 7, 2014

How To Write Python Plug-ins for the GIMP in OS X

I am giving you the lowdown on writing plug-ins for the GIMP (2.8.1) in OS X (Mavericks).  Writing the plug-ins is not hard once you know the ins and outs (which are not well documented on the web).  I spent the better part of a day Googling for answers.  So here is what I learned:

The location of where you put the plug-ins changed when the GIMP came out with a native version for OS X.  I never did get an answer to this by Googling.  I finally just went through each subfolder of GIMP.app until I found it: /Applications/GIMP.app/Contents/Resources/lib/gimp/2.0/plug-ins

There is a very handy tool in the called Python-Fu in GIMP that lets you use Python interactively from within GIMP.  You can find it at Filters->Python-Fu->Console

You can get a list of commands at Help->Procedure Browser.  But before you use a procedure you must:


  •  import gimpfu 
  •  prepend the command with pdb(.) 
  •  change the dashes to underscores 
For example, if you want to use the procedure gimp-file-save, you need to  import gimpfu then change it to pdb.gimp_file_save(parameters)  I really want to thank Hubert and Sebastian Soyer, the authors of the blog "Bits and bobs to remember" for clueing me in on the syntax. 

When Python-Fu calls another plug-in you don't specify a run mode.  If you browse to gimp-file-save in the procedure browser, the documentation lists the parameters as:

  • run-mode - INT32 - The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1), RUN-WITH-LAST-VALS (2) }
  • image - IMAGE - Input image
  • drawable - DRAWABLE - Drawable to save
  • filename - STRING - The name of the file to save the image in
  • raw-filename - STRING - The name as entered by the use
So you might think that you have to enter 5 parameters, right?  Nah.  You skip the run-mode parameter.  So there are only 4 parameters.  By the way,
  • you can get a list of all open images with imageArray = gimp.image_list()
  • then you can get one image by accessing it within the array  img = imageArray[#]
  • you can get the active drawable for the image with imgDrawable = pdb.gimp_image_get_active_drawable(img)
  • You can also obtain the DRAWABLE with imgDrawable = pdb.gimp_image_merge_visible_layers(img, The type of merge { EXPAND-AS-NECESSARY (0), CLIP-TO-IMAGE (1), CLIP-TO-BOTTOM-LAYER (2) })
  • You can get the filename of the image with fn = pdb.gimp_image_get_filename(img)
  • Since this is not interactive with the user, you use the same filename for both parameters
The template for writing the plug-in is well documented on the web. You can find here.  Don't forget to make your plug-in executable with
$ chmod 755 <filename.py>


I hope these hints helped you in some way.  If you have any more insights, please leave a comment.


Tuesday, March 4, 2014

Doughnuts for Dinner

My mother was 100% Irish American. But when she was a newlywed a colleague (probably German or Polish American) brought in doughnuts on Mardi Gras (Fat Tuesday).  She thought that was a great idea so she started a family tradition of making doughnuts on Fat Tuesday.  She only made doughnuts once a year and we always looked forward to them.  I have carried on that tradition with my family but with a wrinkle.

Mother's Doughnuts Recipe
 When the kids were little I was always up early anyway so I tried to make the doughnuts for breakfast.  I would end up flustered and frustrated trying to get them done before the kids went to school.  Then I remembered that Mother always made them during the day and served them up for an after school snack.  After a little bit more thought I figured that if you could have doughnuts for breakfast, why couldn't you have them for dinner? Yup, that's right. Doughnuts for dinner.  No four food groups on Mardi Gras!!

Mother always used the recipe from the Good Housekeeping Cookbook that she got as a shower gift in 1947.  When I would make them, though, they would end up heavy, undercooked and/or over-browned.  Don't get me wrong, my family and friends still loved them but I thought I could do better.

I eventually ended up making them with my own recipe that I glammed together from the original and other recipes that I found along the way.  The biggest contributor was a recipe that I found on Cook's Illustrated.

That took care of the heavy part but they were still coming out either too done or undercooked or both.  I finally broke down and bought an electric fryer that I LOVE. I use it a couple of times a week.

So here's the recipe.  ENJOY!!