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
| #!/usr/bin/env python
# Hello World in GIMP Python
from gimpfu import *
def hello_world(initstr, font, size, color) :
# First do a quick sanity check on the font
if font == 'Comic Sans MS' :
initstr = "Comic Sans? Are you sure?"
# Make a new image. Size 10x10 for now -- we'll resize later.
img = gimp.Image(1, 1, RGB)
# Save the current foreground color:
pdb.gimp_context_push()
# Set the text color
gimp.set_foreground(color)
# Create a new text layer (-1 for the layer means create a new layer)
layer = pdb.gimp_text_fontname(img, None, 0, 0, initstr, 10,
True, size, PIXELS, font)
# Resize the image to the size of the layer
img.resize(layer.width, layer.height, 0, 0)
# Background layer.
# Can't add this first because we don't know the size of the text layer.
background = gimp.Layer(img, "Background", layer.width, layer.height,
RGB_IMAGE, 100, NORMAL_MODE)
background.fill(BACKGROUND_FILL)
img.add_layer(background, 1)
# Create a new image window
gimp.Display(img)
# Show the new image window
gimp.displays_flush()
# Restore the old foreground color:
pdb.gimp_context_pop()
register(
"python_fu_hello_world",
"Hello world image",
"Create a new image with your text string",
"Akkana Peck",
"Akkana Peck",
"2010",
"Hello world (Py)...",
"", # Create a new image, don't work on an existing one
[
(PF_STRING, "string", "Text string", 'Hello, world!'),
(PF_FONT, "font", "Font face", "Sans"),
(PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
(PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
],
[],
hello_world, menu="<Image>/File/Create")
main() |
Partager