Next Previous Table of Contents
Plugin support is probably the most powerfull feature of Babygimp. So you should read this section carefully and be able to create your own plugins in order to get the most out of Babygimp.
Babygimp provides only a very limited set of tools (no despeckling, no text drawing, only primitive smoothing and so on). On the other hand there exist lots of console programs which provide all functions your are missing in Babygimp. For example the Netpbm package and ImageMagick should be present on virtually every Linux system.
So why reinvent the wheel? What one really needs is a facility to use the large set of already existing tools without leaving Babygimp (i.e. saving the image, consulting the manpage, applying the external program, reimporting the output). It would also be usefull to apply external programs to a selected region of the image. There should also be a comfortable way specify command line options for external programs from the Babygimp GUI. This facility is provided by Babygimps plugin mechanism.
Some possible applications of the plugin mechanism are
Suppose, you have an image like this:
Now, you want to transform the border in such a way, that the image looks like a button:
Of course, this effect could be achieved by hand, but this would be some work.
Now suppose, that you have ImageMagick installed on your system. Then this effect can be achieved by the program convert. So, without plugins, you would first consult the convert(1) manpage, then save this image, say to apollo.gif, then transform it using e.g.
$ convert -raise 2x2 apollo.gif apollo2.gif
and finally reload it for further processing.
The plugin mechanism allows you to pipe images (or even regions of an image) through external commands like convert without leaving Babygimp. Numerical parameters can be set in a comfortably manner through sliders.
Once you have created the plugin, the above effect can be achieved whithout leaving Babygimp by calling the plugin:
You may think now that you have to learn Perl/Tk and a complicated API in order to create the GUI for your own plugins. However things are much simpler: Babygimps builtin plugin editor lets you your own plugins in a minute.
Let us see, how the above plugin was created. To this end we invoke the plugin editor from the ``Plugins...'' menu (screenshot reduced to 75 %):
First, we have to determine the plugin type:
Our plugin is a filter; but since it this effect does not change the image size, we select region filter. This enables us to apply the filter also to selected regions.
The alias is the name under which the plugin will appear in the ``Plugins...'' menu. In this example i called it ``MagickRaise'', since it uses ImageMagick.
Now whe need the shell command. Recall that it must read an xpm from stdin and write an xpm to stdout. A look at the convert(1) manpage tells us, that we have to call it as
convert -raise <width>x<height> - xpm:-
But we want to be able to set the <width> and <height> parameters from the plugin menu instead of using a fixed width and height. To this end, the plugin editor allows you to specify formal parameters:
In our example, we have to integer parameters (<width> and <height>), so our shell command will be
convert -raise $int1x$int2- xpm:-
Each time you type something in the shell command entry field, the plugin editor parses the shell command in order to detect formal parameters. As soon as the formal parameters $int1 and $int2 are found you will see additional fields where you may specify aliases, defaults and ranges (screenshot reduced to 75 %):
In our example, the aliases would be the labels of the sliders in the plugin dialog window. Now pressing the preview button will show, how the plugin dialog will look (the apply button is disabled in preview mode).
In order to see, what is really going on, change the slider values in the preview window and press the info button.
It is usefull, to test plugins form the commandline before calling them from Babygimp, e.g.
$ cat test.xpm | convert -raise 13x5 - xpm:- > output.xpm
in this example.
Now we may use this plugin, as if it where a builtin function.
Most plugins will contain only integer or float parameters. In earlier versions, plugins with file parameters where used to import and export file formats other than xpm. This is now obsolete. String and font parameters may be used in order to create images containing text.
In order to create your own plugins you should consult the convert(1) manpage. Try also ``apropos ppm'' in order to get some ideas. The program ppmforge creates really cool backgrounds.
Plugins are stored in $HOME/.babygimp/plugins/<alias>.bpl. You may recover inadvertently changed or deleted plugins since Babygimp creates backups of the plugin files in the same directory. If you want to restore them, just remove the extension .bak and then invoke the rescan plugins function from the plugins menu.. If you want to rename a plugin by hand you must also change the alias.field in the plugin file. Since plugins contain shell commands, they are possible security holes. Therefore Babygimp ignore or plugins if others than the user (or root) has write permission. I am however not sure wheather this is safe on systems where users can ``donate'' files to other users.
If the plugin is a (region) filter, the image (region) is stored to the file $HOME/.babygimp/tmp/plugin_input.xpm. Then Babygimp invokes the shell command
cat $tmpdir/plugin_input.xpm | $command > $tmpdir/plugin_output.xpm
where $tmpdir is $HOME/.babygimp/tmp and $command is the substituted shell command. Finally Babygimp tries to read the file $HOME/.babygimp/tmp/plugin_output.xpm. Of course it would be (slightly) more efficient to use double pipes instead of temporary files. However this might also lead to subtle blocking problems when the external program does not buffer its output. So for simplicity i choosed the primitive approach. Creators would not raise this problem (only a single pipe), but in order to keep the plugin mechanism uniform i decided that also in this case temporaries are used
If a program you want to incorporate in a plugin does not support standard input and standard output you will have to create temporary files. Babygimp itself creates temporary files in the directory $HOME/.babygimp/tmp/ (for filter plugins this is easier than using a double pipe which might lead to blocking problems). These temporary files are plugin_input.xpm and plugin_output.xpm. It is a good idea for plugins to store temporary files in this directory instead of /tmp/.