You are on page 1of 2

Python und Gimp

Python is eine sehr gute Programmiersprache, die in zahllosen Projecten benutzt werden kann (und
wird!).
Wenn man Python auf seinem PC hat und dann Gimp (Gnu Image Processing) installiert, kann man
GIMP auch auf Python hören lassen, d.h. unter anderem selbst 'plug-in' 's mit Python erstellen.

Warum? Gimp kann doch schon 'scripten' mit Tiny Scheme? Ja, das geht teilweise vortrefflich, aber
die Sprache heisst nicht für nichts 'Tiny'.
Python ist halt 'erwachsen' und Tiny Scheme noch ein 'Kind' … na ja, es sei mir erlaubt die beiden
Sprachen so miteinander zu vergleichen.

Hier ein Beipspiel von Raimond Ostertag mit einer kleinen Erweiterung von mir (PKHG).
=============start createNewImage.py =======================
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Template-create python-fu pour Gimp 2.6


# Copyright Raymond Ostertag 2007-2009
# Licence GPL

# PKHG resolution added 2009 mrt 6

# Version 2.1
# - ported to gimp-2.6, menu entry changed to Files/Create
# - generic name changed from Template-xtns to Template-create
# - changed RGB to RGBA_IMAGE for layers with transparent fill
# Version 2.0
# - use gettext
# Version 1.0
# - initial release

# Installation : put the template-create.py file in your $HOME/.gimp-2.n/plug-ins.


# On Linux and Mac OSX the file must be executable.
# Documentation : http://www.gimp.org/docs/python/index.html

from gimpfu import *

# i18n
#
import gettext
locale_directory = gimp.locale_directory
gettext.install( "gimp20-template" , locale_directory, unicode=True )

#
Template_create_help = _("Create an new image with a Background layer and add N empty
layers.")
Template_create_description = _("Python-fu template for Gimp 2.6.")+" "+Template_create_help

def python_fu_template_create( new_image_width, new_image_height,


NbLayer,XResolution,YResolution,FillType ):
new_image = gimp.Image( new_image_width, new_image_height, RGB ) #Create a new image
pdb.gimp_image_set_resolution(new_image, XResolution, YResolution)
new_layer = gimp.Layer(new_image, _("Background"), new_image.width, new_image.height,
RGBA_IMAGE, 100, NORMAL_MODE)
new_image.add_layer(new_layer, 0)
new_layer.fill( FillType )
for i in range( NbLayer ) :
new_layer = gimp.Layer(new_image, _("New Layer"), new_image.width, new_image.height,
RGBA_IMAGE, 100, NORMAL_MODE)
new_image.add_layer(new_layer, 0)
# new_layer.fill( FillType )
gimp.Display( new_image )

register(
"python-fu-template-create",
Template_create_description,
Template_create_help,
"Raymond Ostertag",
"GPL License",
"2007-2009",
_("create new image"),
"",
[
(PF_INT, "new_image_width", _("Width"), "300"),
(PF_INT, "new_image_height", _("Height"), "200"),
(PF_INT, "NbLayer", _("Number of extra layers"), 0),
(PF_INT, "XResolution",_("X resolution"), 75),
(PF_INT, "YResolution",_("Y resolution"), 75),
(PF_RADIO, "FillType", _("Fill with"), 3,
((_("Foreground"), 0),
(_("Background"), 1),
(_("White"), 2),
(_("Transparent"), 3),
(_("Pattern"), 4)
)),
],
[],
python_fu_template_create,
menu="<Image>/Python-Fu",
domain=("gimp20-template", locale_directory)
)

main()
=============end createNewImage.py =======================

Stimmt, hier ist noch kein 'erwachsenenes' Python zu sehen.


Es ist gedacht als Beispiel: Ein 'plug-in' nach eigenen Wünschen erweiteren (resolution).

You might also like