File: plugins.html

package info (click to toggle)
babygimp 0.41-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 584 kB
  • ctags: 236
  • sloc: perl: 5,872; makefile: 48
file content (228 lines) | stat: -rw-r--r-- 9,694 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title>Babygimp Manual - Plugins</title>
  <meta name="GENERATOR" content="amaya V5.0">
</head>

<body bgcolor="#FFFFFF" lang="en">
<p><a href="troubleshooting.html">Next </a> <a
href="clipboard.html">Previous</a>  <a href="index.html">Table of
Contents</a></p>
<hr>

<h1>Plugins</h1>

<p></p>

<p><strong>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.</strong></p>

<h2>Overview</h2>

<p>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.</p>

<p>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.</p>

<p>Some possible applications of the plugin mechanism are</p>
<ul>
  <li>Merging text in your images</li>
  <li>Creating cool fractal backgrounds</li>
  <li>Applying filters (smoothing, despeckling, distorts, ...) to your image.
    <p></p>
  </li>
</ul>

<h2>Example</h2>

<p>Suppose, you have an image like this:</p>

<p><img src="apollo.gif" alt="[Example]"></p>

<p>Now, you want to transform the border in such a way, that the image looks
like a button:</p>

<p><img src="apollo2.gif" alt="[Example]"></p>

<p>Of course, this effect could be achieved by hand, but this would be some
work.</p>

<p>Now suppose, that you have ImageMagick installed on your system. Then this
effect can be achieved by the program <strong>convert.</strong> 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.</p>
<pre>$ convert -raise 2x2 apollo.gif apollo2.gif</pre>

<p>and finally reload it for further processing.</p>

<p>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.</p>

<p>Once you have created the plugin, the above effect can be achieved
whithout leaving Babygimp by calling the plugin:</p>

<p><img src="plugindialog.gif" alt="[Screenshot]"></p>

<p></p>

<p>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 <strong>plugin editor </strong>lets you
<strong>your own plugins in a minute</strong>.</p>

<p>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 %):</p>

<p><img src="plugineditor1.gif" alt="[Screenshot]"></p>

<p>First, we have to determine the <strong>plugin type</strong>:</p>
<ul>
  <li><strong>Filters</strong>
     are shell commands, which are expected to read a xpm from stdin and
    write a xpm to stdout.</li>
  <li><strong>Regionfilters</strong>
     are like filters, but they must not change the the image size. These
    will also appear in the popup menu, when a <a
    href="regions.html"></a>region of the image is selected.</li>
  <li><strong>Creators</strong>
     have no input and write a xpm to stdout. The output xpm will then appear
    in the <a href="clipboard.html">clipboard.</a></li>
</ul>

<p>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.</p>

<p>The <strong>alias</strong> is the name under which the plugin will appear
in the ``Plugins...'' menu. In this example i called it ``MagickRaise'',
since it uses ImageMagick.</p>

<p>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</p>
<pre>convert -raise &lt;width&gt;x&lt;height&gt; - xpm:-</pre>

<p>But we want to be able to set the &lt;width&gt; and &lt;height&gt;
parameters from the plugin menu instead of using a fixed width and height. To
this end, the plugin editor allows you to specify <strong>formal
parameters</strong>:</p>
<ul>
  <li><strong>Integer parameters</strong>
     have the form <span style="font-family: courier">$int1</span>, <span
    style="font-family: courier">$int2</span>, ...</li>
  <li><strong>Float parameters</strong>
     have the form $float1, $float2, ...</li>
  <li><strong>String parameters</strong>
     have the form <span style="font-family: courier">$string1</span>, <span
    style="font-family: courier">$string2</span>, ...</li>
  <li><strong>File parameters</strong>
     have the form <span style="font-family: courier">$file1</span>, <span
    style="font-family: courier">$file2</span>, ...</li>
  <li><strong>Font parameters</strong>
     have the form <span style="font-family: courier">$font1</span>, <span
    style="font-family: courier">$font2</span>, ...</li>
</ul>

<p>In our example, we have to integer parameters (&lt;width&gt; and
&lt;height&gt;), so our shell command will be</p>
<pre>convert -raise $int1x$int2- xpm:-</pre>

<p>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 %):</p>

<p><img src="plugineditor2.gif" alt="[Screenshot]"></p>

<p>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).</p>

<p>In order to see, what is really going on, change the slider values in the
preview window and press the info button.</p>

<p><img src="plugininfo.gif" alt="[Screenshot]"></p>

<p>It is usefull, to test plugins form the commandline before calling them
from Babygimp, e.g.</p>
<pre>$ cat test.xpm | convert -raise 13x5 - xpm:- &gt; output.xpm</pre>

<p>in this example.</p>

<p>Now we may use this plugin, as if it where a builtin function.</p>

<p></p>

<p>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.</p>

<p>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.</p>

<p></p>

<h2>Internals</h2>

<p>Plugins are stored in $HOME/.babygimp/plugins/&lt;alias&gt;.bpl. <a
name="recover">You may recover inadvertently changed or deleted plugins since
Babygimp creates backups of the plugin files in the same directory. </a><a
name="recover1"> 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. </a>Since plugins contain shell commands, they are possible
<strong>security holes</strong>. 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.</p>

<h2>Temporary files</h2>

<p>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</p>
<pre>cat $tmpdir/plugin_input.xpm | $command &gt; $tmpdir/plugin_output.xpm</pre>

<p>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</p>

<p>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/.</p>

<p></p>
<hr>

<p><a href="troubleshooting.html">Next </a> <a
href="clipboard.html">Previous</a>  <a href="index.html">Table of
Contents</a></p>
</body>
</html>