Standalone Scripts
It is possible to write Gimp-Perl scripts that can be executed directly from the command line rather than from within the Gimp’s user interface. The Gimp::Fu module will even start up the Gimp if it is not already running. Because of the length of time it takes for the Gimp to load, however, you probably want to execute standalone scripts that communicate with an instance of the Gimp that is already running. This communication is handled on the script’s side by the Gimp::Net module, and on the Gimp’s side by the Perl Server extension.
To launch the Perl Server, select the <Toolbox> → Xtns → Perl → Server menu option. You’ll see a message on the command line stating that the Perl Server is now accepting connections.
Tip
If you do not explicitly launch the Perl Server from the Xtns menu, a separate instance of the Gimp is launched each time the script is run. This adds many seconds to the runtime of your script.
Launching the Perl Server extension creates a socket through
which local scripts may communicate with the Gimp. You can also tell
the Perl Server to listen on a TCP port (10009 is the default) by
setting the GIMP_HOST
environment
variable before starting the Gimp. See the Gimp::Net manpages for a
complete discussion of this behavior.
When writing a standalone Gimp-Perl script, you should not
register the script with the Gimp’s PDB. All you need to do is define
a net( )
subroutine and register it
with the Gimp::on_net( )
function.
Example 5-3 is a standalone script ...
Get Perl Graphics Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.