Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plug in bump map: Works manually, but not using a Python procedure
#1
Hello fellow Gimp users,

In order to format names that will appear on a game board, I've created a Python script in which for each group associated to a city name, one layer is a bump map and another one is a layer on which I'd like to apply the bump map.

I've been trying to use the procedure "plug-in-bump-map", but I cannot figure out why it's not applied when I use the script instruction (although no error is returned in the Python console), while it's ok when I manually use the gimp-filter-bump-map menu.
Code:
# remove any current selection
g.gimp_selection_none(img)

# set the parameters to be applied for embossing
azimuth = 135 ; elevation = 22 ; depth = 23

# apply the bump layer to the embossed_letters_layer
# (drawable,bumpmap,azimuth,elevation,depth,xofs,yofs,waterlevel,ambient,compensate,invert,type)
g.plug_in_bump_map(img, embossed_letters_layer, bump_layer, azimuth, elevation, depth, 0, 0, 0, 0, 1, 0, 0)

   
   

Is there something wrong in the parameter settings? I saw a discrepancy between the parameters mentioned in the procedure description (14 including "run-mode") and the expected parameters in the console (13 not including "run-mode"). Then, I didn't include any parameter for "run-mode".

Or is there something else, I'm not aware of... Frankly speaking, I'm quite newbie when it comes to Python programming for Gimp :-)

Thanks in advance for your ideas,

Cheers,

Linett.

--------
Here is my full code so far:
Code:
"""
Script to format city names from a list

There are 2 initial layers / group of layers:
- formatted_names: Group of layers on top to store the resulting formatted texts
- target_layer: This is a text layer with a text in the correct font-family, font-size and margins

For each item in the list:
1. Create a dedicated group of layers within the "formatted_names" group of gimp_layer_set_name,
copy the target layer and replace the text in the copied layer by the name of the current item
2. Create 3 different layers by duplicating the alpha selection from the copied layer:
a. glow behind the name,
b. bump layer, and
c. embossed letters on which the bump map is applied
3. Apply the bump layer to the embossed letters layers
4. Merge all the layers of the group
NB:
1. Make sure that the font setting are ok before launching the Script: foreground colour is #4d4020
2. Make sure that the font-family ("ShangriLaNFSmallCaps") and size are ok (60)
# format text box
# font-family: ShangriLaNFSmallCaps
# font-size: 60
# fill-colour: #4d4020
# bump map: 135, 22, 23
"""


# shortcut to avoid writing gimp.pdb all the time
g = gimp.pdb

# access to list of opened images
images = gimp.image_list()
# identify image opened last
img = images[0]
# get layers of images[0] (last opened image)
# the group of layers should be on top, with at least one textbox layer on top
layers = images[0].layers
print layers

# identify the group of layers ("formatted_names")
group_layer = layers[0]

# identify the layer to duplicate
target_layer = layers[1]
print target_layer

# set the height and width of the layers to be created
drawable_height = 161 #g.gimp_drawable_height(target_layer)
drawable_width = 702 #g.gimp_drawable_width(target_layer)

# provide the list of the city names to be formatted
i = 0
lst = ['Mont Saint-Michel']
print lst[i]

# create a list of group of layers where one group will be used for one city name
name_groups = []

# set lock alpha
g.gimp_layer_set_lock_alpha(target_layer, TRUE)

#####################################################################################
# 1. create a new layer group within the "formatted names" group of layers
name_groups.append(g.gimp_layer_group_new(img))
g.gimp_image_insert_layer(img, name_groups[i], group_layer, 0)  # insert this group of layers into the "formatted names" group of layers
g.gimp_item_set_name(name_groups[i], "g_"+lst[i]) # rename the group of layers as per the city name

# duplicate the target layer in the group of layers "formatted names" and set the text as per the list item
copied_layer = g.gimp_layer_copy(target_layer, TRUE)
g.gimp_image_insert_layer(img, copied_layer, name_groups[i], 0)
g.gimp_text_layer_set_text(copied_layer, lst[i]) #change the text in the textbox

#####################################################################################
# 2.a. create a glow behind the city name
# create a new layer called "glow"
glow = g.gimp_layer_new(img, drawable_width, drawable_height, RGBA_IMAGE, "glow", 90, NORMAL_MODE)
# set lock alpha
g.gimp_layer_set_lock_alpha(copied_layer, TRUE)
# copy the alpha channel to the selection
g.gimp_selection_layer_alpha(copied_layer)
# enlarge the selection by 6 pixels
g.gimp_selection_grow(img, 6)
# feather the selection by 5 pixels
g.gimp_selection_feather(img, 5)
# insert the glow layer behind the other layers of the group
g.gimp_image_insert_layer(img, glow, name_groups[i], 1)
# fill the selection with white
g.gimp_edit_fill(glow, WHITE_FILL)

#####################################################################################
# 2.b. create a bump map to emboss the letters of the city name
# create a new layer called "bump_layer"
bump_layer = g.gimp_layer_new(img, drawable_width, drawable_height, RGBA_IMAGE, "bump_layer", 100, NORMAL_MODE)
# copy the alpha channel to the selection
g.gimp_selection_layer_alpha(copied_layer)
# feather the selection by 5 pixels
g.gimp_selection_feather(img, 5)
# insert the bump layer on top of the other layers of the group
g.gimp_image_insert_layer(img, bump_layer, name_groups[i], 0) # 0 to add the layer on top or 1 to add the layer in the bottom
# fill the selection with white
g.gimp_edit_fill(bump_layer, WHITE_FILL)

#####################################################################################
# 2.c. create a layer of letters that will then be embossed
# create a new layer called "embossed_letters_layer"
embossed_letters_layer = g.gimp_layer_new(img, drawable_width, drawable_height, RGBA_IMAGE, "embossed_letters_layer", 100, NORMAL_MODE)
# copy the alpha channel to the selection
g.gimp_selection_layer_alpha(copied_layer)
# create a new layer called "embossed_letters_layer"
g.gimp_image_insert_layer(img, embossed_letters_layer, name_groups[i], 0) # 0 to add the layer on top or 1 to add the layer in the bottom
# fill the selection with foreground color
g.gimp_edit_fill(embossed_letters_layer, 0) # 0 is for FILL-FOREGROUND

#####################################################################################
# 3. Apply the bump layer to the embossed letters layer
# hide some layers
g.gimp_item_set_visible(copied_layer, FALSE)
g.gimp_item_set_visible(bump_layer, FALSE)
# set the embossed letters layer as active layer
g.gimp_image_set_active_layer(img, embossed_letters_layer)

# remove any current selection
g.gimp_selection_none(img)

# set the parameters to be applied for embossing
azimuth = 135 ; elevation = 22 ; depth = 23

# apply the bump layer to the embossed_letters_layer
# (drawable,bumpmap,azimuth,elevation,depth,xofs,yofs,waterlevel,ambient,compensate,invert,type)
g.plug_in_bump_map(img, embossed_letters_layer, bump_layer, azimuth, elevation, depth, 0, 0, 0, 0, 1, 0, 0)

#####################################################################################
#4. Merge all the layers of the group
Reply


Messages In This Thread
plug in bump map: Works manually, but not using a Python procedure - by LinettRidge - 09-05-2020, 09:43 PM

Forum Jump: