[plug] gimp script-fu

Brad Campbell brad at fnarfbargle.com
Thu Nov 3 02:48:53 WST 2011


is there anyone on the list that has experience (skinned knuckles, knees 
or otherwise) with Gimp and the python-fu plugin when used from the 
command line?

I have a python script, modeled on many I've found sprinkled on the web

#!/usr/bin/env python

from gimpfu import *
from gimpenums import *

def titleblock_batch(f,j,infile,titfile):
     img = pdb.gimp_file_load(infile,infile)
     drawable=pdb.gimp_image_get_active_layer(img)
     pdb.python_fu_insert_titleblock(img,drawable,titfile)
     drawable=pdb.gimp_image_get_active_layer(img)
     pdb.gimp_file_save(img, drawable, infile, infile)
     pdb.gimp_image_delete(img)

register (
     "insert_titleblock_batch",
     "Update TitleBlock (batch)",
     "Updates TitleBlock layer in drawing (batch)",
     "Brad Campbell",
     "",
     "",
     "<Image>/Filters/Fred/U_pdate Titleblock batch...",
     "*",
     [
     (PF_FILE, "arg0", "fred", ""),
     (PF_FILE, "arg1", "foo", ""),
     ],
     [],
     titleblock_batch,
)


main()

This script used to read "titleblock_batch(infile,titfile):"
I spent literally hours trying every possible permutation of command 
line input to make the bloody thing work. After trying some wacky and 
way out stuff I finally figured out that for whatever reason, gimp would 
only accept 5 parameters from the command line, and pass 4 of them onto 
the script (you can imagine how much futzing around I tried to get this 
to work!).

It flatly refuses to parse RUN-NONINTERACTIVE, and I have to use the 
enumerated equivalent of "1".

for i in *.xcf ; do cmd="(python-fu-insert-titleblock-batch 1 0 0 \"$i\" 
\"Title_Block_Overlay.xcf\") (gimp-quit 0)" ; echo $cmd ; gimp 
--console-messages --no-interface --batch "$cmd" ; done

(suggestions on how to make this prettier are most welcome to, my 
bash-fu is almost as bad as my gimp-fu!)

For whatever reason I need the f,j, to make titleblock_batch have 4 
parameters, and thus I need to add the 0 0 prior to the file names to 
make it work. If the 0 0 is any other number, or not a number gimp 
complains loudly as it seems to interpret them as indexes prior to 
passing them to the script.

I now have a working combination, but it seems almost fluke-like in its 
sensitivity to change. I wondered if any other Plugger had toyed with 
this or worse?

I could probably do this in Scheme as a real gimp plugin, but since I 
have a passing knowledge of python and the last plugin I wrote in scheme 
was almost as cryptic to me as perl I figured I'd go with the little I know.

Regards,
Brad



More information about the plug mailing list