home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / lib / gimp / 2.0 / plug-ins / text-brush.py < prev    next >
Encoding:
Python Source  |  2009-08-19  |  3.5 KB  |  94 lines

  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. # Author: Jo├úo Sebasti├úo de Oliveira Bueno
  5. # Copyright: Jo├úo S. O. Bueno (2009), licensed under the GPL v 3.0
  6.  
  7. #   This program is free software: you can redistribute it and/or modify
  8. #   it under the terms of the GNU General Public License as published by
  9. #   the Free Software Foundation; either version 3 of the License, or
  10. #   (at your option) any later version.
  11. #
  12. #   This program is distributed in the hope that it will be useful,
  13. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #   GNU General Public License for more details.
  16. #
  17. #   You should have received a copy of the GNU General Public License
  18. #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. from gimpfu import *
  21. import os
  22.  
  23. gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
  24.  
  25. def text_brush(font_name, font_size, text):
  26.     pdb.gimp_context_push()
  27.     pdb.gimp_context_set_default_colors()
  28.     
  29.     padding = font_size // 4
  30.     img = gimp.Image(font_size + padding, font_size + padding, GRAY)
  31.     img.undo_freeze()
  32.     
  33.     text = text.decode("utf-8")
  34.     for letter in reversed(text):
  35.         layer = img.new_layer(fill_mode=BACKGROUND_FILL)
  36.         text_floating_sel = \
  37.             pdb.gimp_text_fontname(img, layer, 
  38.                                    padding // 2,
  39.                                    padding // 2,
  40.                                    letter.encode("utf-8"),
  41.                                    0,
  42.                                    True,
  43.                                    font_size,
  44.                                    PIXELS, 
  45.                                    font_name)
  46.         if text_floating_sel: 
  47.             #whitespace don't generate a floating sel.
  48.             pdb.gimp_edit_bucket_fill(text_floating_sel,
  49.                                   FG_BUCKET_FILL,
  50.                                   NORMAL_MODE, 100, 1.0,
  51.                                   False,0 ,0)
  52.             pdb.gimp_floating_sel_anchor(text_floating_sel)
  53.  
  54.     file_name = text.lower().replace(" ", "_") + ".gih"
  55.     file_path = os.path.join(gimp.directory, 'brushes', file_name)
  56.     
  57.     pdb.file_gih_save(img, img.layers[0], 
  58.                       file_path, file_path, 
  59.                       100, #spacing
  60.                       text, #description,
  61.                       img.width, img.height,
  62.                       1, 1,
  63.                       1, #dimension
  64.                       [len(text)], #rank - number of cells 
  65.                       1, # dimension again - actual size for the
  66.                          # array of the selection mode
  67.                       ["incremental"])
  68.  
  69.     pdb.gimp_brushes_refresh()
  70.     pdb.gimp_image_delete(img)
  71.     pdb.gimp_context_pop()
  72.  
  73. register(
  74.         "brush-from-text",
  75.          N_("Create a new brush with characters from a text sequence"),
  76.          """New dynamic brush where each cell is a character from 
  77. the input text in the chosen font """,
  78.          "Joao S. O. Bueno",
  79.          "Copyright Joao S.O. Bueno 2009. GPL v3.0",
  80.          "2009",
  81.          N_("New Brush from _Text..."),
  82.          "",
  83.          [
  84.             (PF_FONT,    "font", _("Font"), "Sans"),
  85.             (PF_SPINNER, "size", _("Pixel Size"), 50, (1, 8000, 1)),
  86.             (PF_STRING,  "text", _("Text"), "GNU Image Manipulation Program")
  87.          ],
  88.          [],
  89.          text_brush,
  90.          menu="<Image>/File/Create",
  91.          domain=("gimp20-python", gimp.locale_directory)
  92.         )
  93. main()
  94.