Pella86

GIMP NMS script

Oct 12th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Tutorial available at: https://www.youtube.com/watch?v=nmb-0KcgXzI
  4.  
  5. from gimpfu import *
  6.  
  7. def hello_warning(image, drawable, image2, drawable2):
  8.     if image:
  9.         pdb.gimp_message("current image: " + image.name )
  10.        
  11.         # insert the alpha channel
  12.         layer = image.active_layer
  13.         pdb.gimp_layer_add_alpha(layer)
  14.        
  15.        
  16.         # crop the image
  17.         new_width = 410
  18.         new_height = 250
  19.         offx = 118 + 14
  20.         offy = 322 + 12
  21.        
  22.         pdb.gimp_image_crop(image, new_width, new_height, offx, offy)
  23.        
  24.         # select the white stuff
  25.         operation = CHANNEL_OP_REPLACE
  26.         color = (235, 255, 255)
  27.         sample_threshold = 90.0/255.0
  28.        
  29.         pdb.gimp_context_set_sample_threshold(sample_threshold)
  30.        
  31.         pdb.gimp_image_select_color(image, operation, drawable, color)
  32.        
  33.         # set FG Color to white
  34.         foreground = (255, 255, 255)
  35.         pdb.gimp_context_set_foreground(foreground)
  36.        
  37.         # color selection white
  38.         fill_mode = FG_BUCKET_FILL
  39.         paint_mode = NORMAL_MODE
  40.         opacity = 100
  41.         threshold = 0
  42.         sample_merged = 0
  43.         x = 0
  44.         y = 0
  45.         pdb.gimp_bucket_fill(drawable, fill_mode, paint_mode, opacity, threshold, sample_merged, x, y)
  46.        
  47.         # invert selection
  48.         pdb.gimp_selection_invert(image)
  49.        
  50.         # delete stuff
  51.         pdb.gimp_edit_clear(drawable)
  52.  
  53.         # invert selection again
  54.         pdb.gimp_selection_invert(image)
  55.        
  56.         # make selection bigger
  57.         steps = 3
  58.         pdb.gimp_selection_grow(image, steps)
  59.        
  60.         # create new layer
  61.         width = image.active_layer.width
  62.         height = image.active_layer.height
  63.         type = RGBA_IMAGE
  64.         name = "text background"
  65.         opacity = 100
  66.         mode = NORMAL_MODE
  67.         layer_textbg = pdb.gimp_layer_new(image, width, height, type, name, opacity, mode)        
  68.        
  69.         position = 1
  70.         pdb.gimp_image_add_layer(image, layer_textbg, position)
  71.        
  72. #        # select layer
  73.         image.active_layer = layer_textbg
  74.  
  75.         # set FG Color to black
  76.         foreground = (0, 0, 0)
  77.         pdb.gimp_context_set_foreground(foreground)  
  78.        
  79.         # fill selection with black
  80.         fill_mode = FG_BUCKET_FILL
  81.         paint_mode = NORMAL_MODE
  82.         opacity = 100
  83.         threshold = 0
  84.         sample_merged = 0
  85.         x = 0
  86.         y = 0
  87.         pdb.gimp_bucket_fill(layer_textbg, fill_mode, paint_mode, opacity, threshold, sample_merged, x, y)
  88.        
  89.         # select layer '0
  90.         merge_layer = image.layers[0]
  91.         merge_type = EXPAND_AS_NECESSARY
  92.         layer = pdb.gimp_image_merge_down(image, merge_layer, merge_type)  
  93.        
  94.         # select all
  95.         pdb.gimp_selection_all(image)
  96.        
  97.         # copy
  98.         drawable = image.active_layer
  99.         non_empty = pdb.gimp_edit_copy(drawable)
  100.         if non_empty:
  101.             pdb.gimp_message("copy successful" )
  102.            
  103.         # create a new layer in the second image
  104.         width = new_width
  105.         height = new_height
  106.         type = RGBA_IMAGE
  107.         name = "information text"
  108.         opacity = 100
  109.         mode = NORMAL_MODE
  110.         layer_info = pdb.gimp_layer_new(image2, width, height, type, name, opacity, mode)              
  111.        
  112.         position = 0
  113.         pdb.gimp_image_add_layer(image2, layer_info, position)
  114.  
  115.                
  116.         # paste image
  117.        
  118.         drawable = image2.active_layer
  119.         paste_into = True
  120.        
  121.         floating_sel = pdb.gimp_edit_paste(drawable, paste_into)
  122.         pdb.gimp_floating_sel_anchor(floating_sel)
  123.        
  124.     else:
  125.         pdb.gimp_message("No image loaded")
  126.    
  127.  
  128. register(
  129.     "python-fu-Hello-Warning",
  130.     "simply a test",
  131.     "simply a test but longer description",
  132.     "Me", "Myself", "2018",
  133.     "Hello warning",
  134.     "", # type of image it works on (*, RGB, RGB*, RGBA, GRAY etc...)
  135.     [
  136.         # basic parameters are: (UI_ELEMENT, "variable", "label", Default)
  137.         (PF_IMAGE, "image", "takes current image", None),
  138.         (PF_DRAWABLE, "drawable", "Input layer", None),
  139.         (PF_IMAGE, "image2", "takes current image", None),
  140.         (PF_DRAWABLE, "drawable2", "Input layer", None)
  141.         # PF_SLIDER, SPINNER have an extra tuple (min, max, step)
  142.         # PF_RADIO has an extra tuples within a tuple:
  143.         # eg. (("radio_label", "radio_value), ...) for as many radio buttons
  144.         # PF_OPTION has an extra tuple containing options in drop-down list
  145.         # eg. ("opt1", "opt2", ...) for as many options
  146.         # see ui_examples_1.py and ui_examples_2.py for live examples
  147.     ],
  148.     [],
  149.     hello_warning, menu="<Image>/My scripts")  # second item is menu location
  150.  
  151. main()
Advertisement
Add Comment
Please, Sign In to add comment