#!/usr/bin/env python # #Copyright (C) 2006 Jason Kivlighn # #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_gen_corners( radius, fg_color, bg_color, file_prefix, directory ): height = width = radius*2 img = gimp.Image(width, height, RGB) drawable = gimp.Layer(img, "Corner Layer", width, height, RGB_IMAGE, 100, NORMAL_MODE) pdb.gimp_image_add_layer(img,drawable,0) gimp.set_foreground(fg_color) gimp.set_background(bg_color) pdb.gimp_drawable_fill(drawable,BACKGROUND_FILL) pdb.gimp_ellipse_select(img,0,0,radius*2,radius*2,CHANNEL_OP_REPLACE,TRUE,FALSE,0) pdb.gimp_edit_bucket_fill(drawable,FG_BUCKET_FILL,NORMAL_MODE,100,1,FALSE,0,0) pdb.gimp_rect_select(img,0,0,radius,radius,CHANNEL_OP_REPLACE,FALSE,0) pdb.gimp_edit_copy(drawable) tl_img = gimp.Image(radius, radius, RGB) tl_drawable = gimp.Layer(tl_img, "Top Left", radius, radius, RGB_IMAGE, 100, NORMAL_MODE) pdb.gimp_image_add_layer(tl_img,tl_drawable,0) pdb.gimp_floating_sel_anchor(pdb.gimp_edit_paste(tl_drawable,TRUE)) pdb.gimp_rect_select(img,radius,0,radius,radius,CHANNEL_OP_REPLACE,FALSE,0) pdb.gimp_edit_copy(drawable) tr_img = gimp.Image(radius, radius, RGB) tr_drawable = gimp.Layer(tr_img, "Top Right", radius, radius, RGB_IMAGE, 100, NORMAL_MODE) pdb.gimp_image_add_layer(tr_img,tr_drawable,0) pdb.gimp_floating_sel_anchor(pdb.gimp_edit_paste(tr_drawable,TRUE)) pdb.gimp_rect_select(img,0,radius,radius,radius,CHANNEL_OP_REPLACE,FALSE,0) pdb.gimp_edit_copy(drawable) bl_img = gimp.Image(radius, radius, RGB) bl_drawable = gimp.Layer(bl_img, "Bottom Left", radius, radius, RGB_IMAGE, 100, NORMAL_MODE) pdb.gimp_image_add_layer(bl_img,bl_drawable,0) pdb.gimp_floating_sel_anchor(pdb.gimp_edit_paste(bl_drawable,TRUE)) pdb.gimp_rect_select(img,radius,radius,radius,radius,CHANNEL_OP_REPLACE,FALSE,0) pdb.gimp_edit_copy(drawable) br_img = gimp.Image(radius, radius, RGB) br_drawable = gimp.Layer(br_img, "Bottom Right", radius, radius, RGB_IMAGE, 100, NORMAL_MODE) pdb.gimp_image_add_layer(br_img,br_drawable,0) pdb.gimp_floating_sel_anchor(pdb.gimp_edit_paste(br_drawable,TRUE)) filename = directory+"/"+file_prefix+"tr.png" pdb.file_png_save_defaults( tr_img, tr_drawable, filename, filename ) filename = directory+"/"+file_prefix+"tl.png" pdb.file_png_save_defaults( tl_img, tl_drawable, filename, filename ) filename = directory+"/"+file_prefix+"br.png" pdb.file_png_save_defaults( br_img, br_drawable, filename, filename ) filename = directory+"/"+file_prefix+"bl.png" pdb.file_png_save_defaults( bl_img, bl_drawable, filename, filename ) register( "python_fu_gen_corners", "Generate four rounded corners", "Generate four rounded corners. Useful for writing web pages with many rounded corners.", "Jason Kivlighn", "Jason Kivlighn", "2006", "/Xtns/Python-Fu/_Generate Corners", "RGB*, GRAY*", [ (PF_INT, "radius", "Radius", 10), (PF_COLOR, "fg_color", "Foreground Color", (255,255,255)), (PF_COLOR, "bg_color", "Background Color", (0,0,0)), (PF_STRING, "file_prefix", "File prefix", "border_"), (PF_FILE, "directory", "Directory", "") ], [], python_gen_corners) main()