#!/usr/bin/env python # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import math from gimpfu import * def python_legofy(img, tdrawable, size=20): orig_width = img.width orig_height = img.height # Patterns are 20x20 pixels. We resize the image to simulate # different lego sizes scale = 20/float(size) width = orig_width * scale height = orig_height * scale pdb.gimp_image_scale(img, width, height) # Pixelize the active layer bkgnd_layer = pdb.gimp_image_get_active_drawable(img) pdb.plug_in_pixelize2(img, bkgnd_layer, 20, 20) # Apply the two lego patterns Patrick Mahoney # provided. layer_one = gimp.Layer(img, "Lego", width, height, RGB_IMAGE, 100, MULTIPLY_MODE) layer_two = gimp.Layer(img, "Lego Highlight", width, height, RGB_IMAGE, 50, ADDITION_MODE) img.add_layer(layer_one, 0) img.add_layer(layer_two, 0) pdb.gimp_edit_fill(layer_one, TRANSPARENT_FILL) pdb.gimp_edit_fill(layer_two, TRANSPARENT_FILL) orig_pattern = pdb.gimp_context_get_pattern() pdb.gimp_context_set_pattern("lego 1x1 brick") pdb.gimp_bucket_fill(layer_one, PATTERN_BUCKET_FILL, NORMAL_MODE, 100, 255, 0, 0, 0) pdb.gimp_context_set_pattern("lego 1x1 brick highlight") pdb.gimp_bucket_fill(layer_two, PATTERN_BUCKET_FILL, NORMAL_MODE, 100, 255, 0, 0, 0) # Set current pattern back to original pattern pdb.gimp_context_set_pattern(orig_pattern) # Re-scale image to original size pdb.gimp_image_scale(img, orig_width, orig_height) register( "python_fu_legofy", "Make the specified layer look like it is made of legos", "Make the specified layer look like it is made of legos", "Peter Tyser", "Peter Tyser", "2006", "/Python-Fu/Alchemy/_Legofy", "RGB*, GRAY*", [ (PF_INT, "size", "Lego Size in Pixels", 3) ], [], python_legofy) main()