You are here

Executing C plug-in in batch mode -- help!

Hi GIMP Experts,

I can't find an example of calling a GIMP plug-in that is written in C. It seems that there are a lot of them using Python and/or Script-Fu. Could someone please provide me an example of how to invoke a C plug-in from the command line using batch mode? Thanks so much in advance!

Sincerely,
GIMP Student

Most of the built-in/bundled plugins are written in C. You call them exactly the same way as any, using the pdb call.

-Rob A>

Thanks Rob so much for your response!

I found C plug-ins are not that friendly.... I can't find a pure batch mode example using C plug-in. At the moment I am going to try Script-Fu.

(Wondering what that “Fu” means – I am sure it is not First Union.)

Sincerely,
GIMP Student

"(Wondering what that 'Fu' means – I am sure it is not First Union.)"

The "-fu" in Script-fu is an homage to the martial art of Kung Fu. In the good ol' days, the term would often be used when referring to a hacker's skills ("Joe sure has some good debugging-fu").

To be more specific, you would use the Script-fu interpreter in batch mode to invoke your plug-in.

For example,

gimp -i -b "(let ((image (car (file-load 1 \"foo.jpg\" \"foo.jpg\"))))
              (plug-in-antialias 1 image (car (gimp-image-get-active-layer))))"

Of course you will need to save your image afterward else your changes will be lost.

Thanks so much for the guidance!

I end up building gimp-2.6.11. Because the hard time I am having with running C plug-ins from command line, I am switching to Script-Fu at the moment.

My Ubuntu is 11.10, and every time I execute this:

/opt/gimp-2.6/bin/gimp-2.6 -i -b "(elsamuko-photochrom-batch \"my.jpg\" (list 255 128 0) (list 255 68 112) 60 60 0 100 FALSE FALSE)" -b "(gimp-quit 0)"

I get the crazy warning and error:

GLib-WARNING **: /build/buildd/glib2.0-2.30.0/./glib/goption.c:2168: ignoring no-arg, optional-arg or filename flags (8) on option of type 0

batch command experienced an execution error

Could you pleas shed more light in this direction? Is it because of my build is not good or something funky about Ubuntu 11.10?

Sincerely,
GIMP Student

"Is it because of my build is not good or something funky about Ubuntu 11.10?"

Unfortunately, I think this may be the case. Your command line works fine when I use it on my Slackware box running GIMP 2.6.11 with GLIB2 2.28. Please elaborate on how you went about building your GIMP version and what steps you took to clean your system of the original version.

The only plug-in that elsamuko's script uses is auto-crop so we should probably look to see if that plug-in is the one that belongs to the GIMP you are running. I am speculating that it does not; i.e., that it is a leftover from your distro's GIMP while you are using a custom one (or somesuch problem).

Hi Saul,

Thanks so much again for your expertise!

I basically followed the steps described in

http://www.gimpusers.com/tutorials/compiling-gimp-for-ubuntu

to build my GIMP 2.7.2 version. But then I followed these similar steps to build 2.6.11.

I realized that I have not removed anything from the existing software. Since I had so many problems with 2.7.2 I am fully agreeing with you on your assessment.

As the build steps instructed, I also built babl-0.1.2 and gegl-0.1.2 along with gimp build. The basic steps were simply to execute the configure script with prefix set to my /opt/gimp* directory, like the following:

./configure -prefix=/opt/gimp-2.6
sudo make install

And to run the application, I source the lines below before typing in the application name, gimp-2.6

export PREFIX=/opt/gimp-2.6

export PATH=$PREFIX/bin:$PATH

export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig

export LD_LIBRARY_PATH=$PREFIX/lib

Besides these, I had to install libtool, intltool, and some others as dependencies.

I think you mus be correct that I didn't delete existing files. But I thought using LD_LIBRARY in the shell can simple bypass the system GIMP files/libraries. Would you please provide me some explanations/instructions to clean up?

Sincerely,
GIMP Student

> And to run the application, I source the lines below
> before typing in the application name, gimp-2.6
>
> export PREFIX=/opt/gimp-2.6
> export PATH=$PREFIX/bin:$PATH
> export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
> export LD_LIBRARY_PATH=$PREFIX/lib

It should only be necessary to set the $PATH (not even that if you provide a fully qualified path to the binary). $PREFIX and $PKG_CONFIG_PATH are only ever needed when running ./configure and if $LD_LIBRARY_PATH is provided when running ./configure then it is not necessary to specify it when you run the program (the GIMP build will embed the library path into the program).

Can you post the output of running the following command:

ldd /opt/gimp-2.6/bin/gimp-2.6 | grep -E "libgimpbase|glib-2|gegl|babl"

Hi Saul,

Thanks so much! Output is as follows.

ldd /opt/gimp-2.6/bin/gimp-2.6 | grep -E "libgimpbase|glib-2|gegl|babl"
libgimpbase-2.0.so.0 => /opt/gimp-2.6/lib/libgimpbase-2.0.so.0 (0x00007ff3bc0d7000)
libgegl-0.1.so.0 => /opt/gimp-2.6/lib/libgegl-0.1.so.0 (0x00007ff3b9eb5000)
libbabl-0.1.so.0 => /opt/gimp-2.6/lib/libbabl-0.1.so.0 (0x00007ff3b9921000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007ff3b8f50000)

Sincerely,
GIMP Student

I was hoping there'd be something obvious indicated but your dependencies seem reasonable.

As a long shot, try invoking GIMP by specifying the library path explicitly:

LD_LIBRARY_PATH=/opt/gimp-2.6/lib /opt/gimp-2.6/bin/gimp-2.6

If that does not work (and I don't really expect it to) then I would recommend GIMP again following the tutorial (perhaps you missed something, it happens to the best).

I am not that familiar with Ubuntu's approach to compiling programs (I use Slackware precisely because it makes that task trivially easy). You might be better served taking your problem to an Ubuntu support forum.

Hi Saul,

Thanks for the direction again!

I was able to step into the following module:

gimppluginmanager-call.c

for the plug-in main loop to take over control while it called g_main_loop_run (proc_frame->main_loop), which is a GLib function. Then the code returned that batch command error.

I wasn't able to get into Glib to further debug. But it sounds the problem may be in the OS. I like to step into that g_main_loop_run code. Do you think it is a good idea or should I just go into the Ubuntu forum?

By the way, based on the stack trace, I noted the procedure name is plug-in-script-fu-eval.

#0 gimp_plug_in_new (manager=0xbd3040, context=0xc31150, progress=0x0,

procedure=0xf6d020,

prog=0xf6cf00 "/opt/gimp-2.6/lib/gimp/2.0/plug-ins/script-fu")

at gimpplugin.c:218

#1 0x0000000000689216 in gimp_plug_in_manager_call_run (manager=0xbd3040,

context=0xc31150, progress=0x0, procedure=0xf6d020, args=0xf7f2e0,

synchronous=1, display=0x0) at gimppluginmanager-call.c:156

#2 0x000000000067f02a in gimp_plug_in_procedure_execute (procedure=0xf6d020,

gimp=0xbd4050, context=0xc31150, progress=0x0, args=0xf7f2e0,

error=0x7fffffffdde8) at gimppluginprocedure.c:212

#3 0x000000000068f7d3 in gimp_procedure_execute (procedure=0xf6d020,

gimp=0xbd4050, context=0xc31150, progress=0x0, args=0xf7f2e0,

error=0x7fffffffdde8) at gimpprocedure.c:330

#4 0x000000000068b467 in gimp_pdb_execute_procedure_by_name_args (

pdb=0xbd79e0, context=0xc31150, progress=0x0, error=0x7fffffffdde8,

name=0x7c35cc "plug-in-script-fu-eval", args=0xf7f2e0) at gimppdb.c:327

Sincerely,
GIMP Student

It turned out my gimp directory didn't have that scm script-fu file. I learned it the hard way by debugging and some printfs. Thanks for your help on this question.

I am still going to find out how to invoke the C plug-in in batch mode. I think -i -b -batch and -batch_interpreter arguments can help.

Sincerely,
-GIMP Student

Subscribe to Comments for "Executing C plug-in in batch mode -- help!"