1#!/usr/local/bin/python 2 3# Gimp-Python - allows the writing of Gimp plugins in Python. 4# Copyright (C) 1997 James Henstridge <james@daa.com.au> 5# 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 3 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19from gimpfu import * 20 21gettext.install("gimp20-python", gimp.locale_directory, unicode=True) 22 23def shadow_bevel(img, drawable, blur, bevel, do_shadow, drop_x, drop_y): 24 # disable undo for the image 25 img.undo_group_start() 26 27 # copy the layer 28 shadow = drawable.copy(True) 29 img.insert_layer(shadow, position=img.layers.index(drawable) + 1) 30 shadow.name = drawable.name + " shadow" 31 shadow.lock_alpha = False 32 33 # threshold the shadow layer to all white 34 pdb.gimp_threshold(shadow, 0, 255) 35 36 # blur the shadow layer 37 pdb.plug_in_gauss_iir(img, shadow, blur, True, True) 38 39 # do the bevel thing ... 40 if bevel: 41 pdb.plug_in_bump_map(img, drawable, shadow, 135, 45, 3, 42 0, 0, 0, 0, True, False, 0) 43 44 # make the shadow layer black now ... 45 pdb.gimp_drawable_invert(shadow, False) 46 47 # translate the drop shadow 48 shadow.translate(drop_x, drop_y) 49 50 if not do_shadow: 51 # delete shadow ... 52 gimp.delete(shadow) 53 54 # enable undo again 55 img.undo_group_end() 56 57 58register( 59 "python-fu-shadow-bevel", 60 N_("Add a drop shadow to a layer, and optionally bevel it"), 61 "Add a drop shadow to a layer, and optionally bevel it", 62 "James Henstridge", 63 "James Henstridge", 64 "1999", 65 N_("_Drop Shadow and Bevel..."), 66 "RGBA, GRAYA", 67 [ 68 (PF_IMAGE, "image", "Input image", None), 69 (PF_DRAWABLE, "drawable", "Input drawable", None), 70 (PF_SLIDER, "blur", _("_Shadow blur"), 6, (1, 30, 1)), 71 (PF_BOOL, "bevel", _("_Bevel"), True), 72 (PF_BOOL, "shadow", _("_Drop shadow"), True), 73 (PF_INT, "drop-x", _("Drop shadow _X displacement"), 3), 74 (PF_INT, "drop-y", _("Drop shadow _Y displacement"), 6) 75 ], 76 [], 77 shadow_bevel, 78 menu="<Image>/Filters/Light and Shadow/Shadow", 79 domain=("gimp20-python", gimp.locale_directory) 80 ) 81 82main() 83