#!/usr/bin/env python # -*- coding: utf-8 -*- # text-to-image v0.2: Python-fu plugin for GIMP 2.6 # Copyright Nikita Melnichenko [http://nikita.melnichenko.name], 2009-2010 # Licence GPL-2 # Installation: put the file into ~/.gimp-2.n/plug-ins, set executable bit on it. from gimpfu import * import os def python_fu_text_to_image(text, font, font_size, text_color, background_color, background_opacity, path, append_size_to_filename): # set foreground color gimp.set_foreground(text_color) # set background color gimp.set_background(background_color) # create image: width, height, type image = gimp.Image(font_size, font_size, RGB) # create layer with text and add it to the image: image, drawable, x, y, text, border, antialias, size, size_type, fontname text_layer = pdb.gimp_text_fontname(image, None, 0, 0, text, 0, 1, font_size, PIXELS, font) # resize image to layer content pdb.gimp_image_resize_to_layers(image) # autocrop image to fit the text pdb.plug_in_autocrop(image, text_layer) # create layer: image, width, height, type, name, opacity, mode layer = gimp.Layer(image, "background", image.width, image.height, RGBA_IMAGE, background_opacity, NORMAL_MODE) # append layer to the image image.add_layer(layer, 0) # fill layer with color layer.fill(BACKGROUND_FILL) # pull the layer down pdb.gimp_image_lower_layer_to_bottom(image, layer) # merge all layers layer = image.merge_visible_layers(CLIP_TO_IMAGE) # if path is set then save the image if path: # get extension (name, ext) = os.path.splitext(path) # gif needs indexed image if ext == ".gif": # convert to indexed: image, dither_type, palette_type, num_cols, alpha_dither, remove_unused, palette pdb.gimp_image_convert_indexed(image, FS_DITHER, MAKE_PALETTE, 255, 0, 0, "") # insert image size to filename if needed if append_size_to_filename: path = name + "-" + `image.width` + "x" + `image.height` + ext # save result pdb.gimp_file_save(image, layer, path, path) # dislay results try: gimp.Display(image) except: pass register( "python-fu-text-to-image", "Creates image with specified text and saves it to a file", "Creates image with specified text and saves it to a file", "Nikita Melnichenko [http://nikita.melnichenko.name]", "Nikita Melnichenko [http://nikita.melnichenko.name]", "2009-2010", "Just a plain text...", "", [ (PF_STRING, "text", "Text", "Sample text"), (PF_FONT, "font", "Font", "Arial"), (PF_INT, "font_size", "Font size", 100), (PF_COLOR, "text_color", "Text color", (0, 0, 0)), (PF_COLOR, "background_color", "Background color", (255, 255, 255)), (PF_SLIDER, "background_opacity", "Background opacity", 100, (0, 100, 1)), (PF_FILE, "path", "Save as", ""), (PF_BOOL, "append_size_to_filename", "Append image size to file name", 0), ], [], python_fu_text_to_image, menu="/File/Create/Logos", ) main()