Categorieën
LibrePlan

LibrePlan book is in the works, LibrePlan present at T-DOSE conference

Hi all,

I just wanted to give you all an update on what I have been bussy with.

To me one of the most important things is to let you all know that I am currently working very hard on the LibrePlan book. It will be my 10th book but the first one I have written in English.  I guess I need one more month to finish it. When it’s ready, I will publish it on my own space on lulu.com, like all my other books. If you have ideas of things you would really like to see in the book, just drop me an email.

The other newsbit is that the LibrePlan project will be presented at the upcoming T-DOSE conference (www.t-dose.org). At our booth will be a nice/huge LibrePlan banner and the LibrePlan people will wear nice sweaters with LibrePlan logo.

At the T-DOSE conference there will also be a small joke at the LibrePlan booth as you can see in the next image:

20131009_122657_web

We hope to see as many people as possible at the T-DOSE event. So join us!

Kind regards,

Jeroen Baten

Categorieën
English Language

Scripting in Gimp. The hard and the nice way…

Small problem intro…

I am writing another book. I want to add numbered bullets to a screenshot. All bullets added as images each on a separate layer to easy the moving around. This way I can reference these bullets from the text in my book. Well, why not do some scripting in Gimp to make this happen?

It all sounds harmless enough now, doesn’t it?.

First: the hard way…

I thought: “Well, the script-fu scripting language, as is in use in the excellent GIMP program, has been around for a long time. There should be enough example scripts and I will be out of the woods in minutes.”. Well, you can just forget about that.

It is like the Lisp programming language so you will be writing a lot of “(” and “)”.

To find out more about defining the function and registering it with the Gimp program I direct you to other webpages. There is enough info on that in the script-fu tutorial.

Anyway, at the end of a hard days work, I had a script that worked! It added a layer to an image, it loaded a small image and placed it on the new layer and also gave the new layer a name.

It looks like this (beware of the newlines) :

(script-fu-register
  "script-fu-jb-count"                        ;func name
  "JB count"                                  ;menu label
  "add layers with numbers."                  ;description
  "Jeroen Baten"                              ;author
  "copyright 2013, Jeroen Baten"              ;copyright notice
  "October 10 2013"                           ;date created
  ""                                          ;image type that the script works on
  SF-IMAGE    "Image"         0
)

(script-fu-menu-register "script-fu-jb-count" "/Scripts/JB-Scripts")

(define (script-fu-jb-count theImage )
  (let*
    (
    (new-layer1 nil)
    )

    ; Create a new layer
    (set!  new-layer1  (car (gimp-file-load-layer 1 theImage "piclib/1.png" ) ) )
    ; Give it a name
    (gimp-layer-set-name new-layer1 "Laag 1")
    ; Add the new layer to the image
    (gimp-image-add-layer theImage new-layer1 0)
  )
)

Sofar, so good. Turns out there is (almost) no looping possible in script-fu. Well, there is, but you really don’t want to go there (just sayin’).

Second: the nice way:

So I turned to using the Python-fu stuff (I love python). If you compare the two scripts the differences should be easy to spot:

#!/usr/bin/env python

from gimpfu import *

def insert_numbers(theImage,count) :
    new_layer1 = pdb.gimp_file_load_layer(theImage, "piclib/1.png")
    pdb.gimp_layer_set_name(new_layer1,"Laag 1")
    pdb.gimp_image_add_layer(theImage,new_layer1,0)

register(
    "python_fu_jbcount2",
    "Insert numbers",
    "Add layers to an image with counters in them",
    "Jeroen Baten",
    "Jeroen Baten",
    "2013",
    "JBCount2",
    "*",
    [
        (PF_IMAGE, "img", "Image:", None),
        (PF_STRING, "string", "Aantal", '1'),
    ],
    [],
    insert_numbers, menu="/JBCount2")

main()

In short:

  • In all internal Gimp routine names the “-” is replaced with an “_”.
  • A “pdb.” is placed before all internal Gimp routine names.

Now, adding looping to this should be a walk in the park.

Caveats

Beware if the fact that Script-fu stuff belongs in “~/gimp-2.8/scripts”  and Python-fu scripts belongs in “~/gimp-2.8/plug-ins”.