Saturday 12 November 2016

GIMP python Plugin development on Windows 10 using Sublime Text 3

GIMP is a fantastic photo editor and ideal for graphic artists who want to create 2D characters and environmental art. One of its most interesting features is the ability to create custom plug-ins for automating editing and workflow processes. Potentially it could be used to create animated sprite sheets where character components could be programatically posed from frame to frame. This maybe very useful for current work on an game targeted at a Atmega644 8 bit games console.

The steps to creating a Hello World plugin on Windows 10 are as follows;

Step 1

Using File Explorer navigate to GIMP 2 installation plug-ins directory. This custom plug-in was tested with GIMP 2.8.18 available at https://www.gimp.org/downloads/


C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins

Step 2

Run Command Prompt (as administrator). The command prompt must be run as an administrator to enable creation and update of python files within the plug-ins directory.



Step 3

In the command prompt open Sublime Text 3 and hello_world.py file (new file) by typing the following into command prompt;


C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins>"C:\devtools\Sublime Text 3\subl" hello_world.py


Step 4

Type the following code into Sublime Text 3 (Notepad / Idle / or your editor of choice can be used just by changing the editor executable in step 3)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from gimpfu import *

def hello_world():
    pdb.gimp_message('Hello World !....')

    
register(
    'python-fu-hello-world',                            # Plugin unique name
    'Hello World',                                      # Tooltip short name
    'This is a Hello World Plugin',                     # Tooltip long description
    'MuddyGames', 'MuddyGames', '2016',               # Creator, Copyright owner, released
    'HelloWorld',                                      # Menu name
    '*',                                                # Supported image color * <all>
    [],                                                 # Input Parameters
    [],                                                 # Return Parameters
    hello_world,                                        # Method to call
    menu='<Image>/Filters/Render')                      # Menu entry location

main()

Step 5

Launch GIMP and examine the Filters | Render menu and you should now see the Hello World plugin registered within GIMP.



Step 6

Create and new image and the plug-in should be enabled and useable. The Hello World message should appear within the error console [ Windows | Dockable Dialogs | Error Console ]





Would suggest reading http://stackoverflow.com/questions/14592607/installing-pygimp-on-windows

Enjoy writing plugins, the GIMP Plug-ins documentation is located at https://www.gimp.org/docs/python/index.html

As GIMP scripts are run and debugged within the GIMP application the following modified code maybe useful for debugging scripts. It uses system (sys) (to print to file) and datetime (timestamps) modules. It will create a log file within c:\temp. You could add a DEBUG macro / method and only log execution during script development and turn DEBUG off during production.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from gimpfu import *
import datetime
import sys

def hello_world():
    sys.stdout = open( 'c:\\temp\\out.txt', 'a')
    print(datetime.datetime.now())
    print('Hello_World')
    pdb.gimp_message('Hello World !....')
    
register(
    'python-fu-hello-world',                            # Plugin unique name
    'Hello World',                                      # Tooltip short name
    'This is a Hello World Plugin',                     # Tooltip long description
    'Muddy Games', 'Muddy Games', '2016',               # Creator, Copyright owner, released
    'Hello World',                                      # Menu name
    '*',                                                # Supported image color * <all>
    [],                                                 # Input Parameters
    [],                                                 # Return Parameters
    hello_world,                                        # Method to call
    menu='<Image>/Filters/Render')                      # Menu entry location

main()


1 comment: