Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching for python script islands to layers
#10
Wow, that's a lot to take in, I'm really a novice at this, a lot of studying to do...
Meanwhile I made a small script that works by going every 10 pixels, use color picker, if alpha is bigger than 0, use fuzzy select tool etc.
I also have to apply the mask layer for this script to work, thankfully the color data of the transparent pixels is preserved.

Code:
img = gimp.image_list()[0]
layer = img.active_layer
#sample every 10 pixels
sample = 10
for i in range(img.height/sample):
#for i in range(img.width/sample):
    for j in range(img.width/sample):
    #for j in range(img.height/sample):
        alphacheck = pdb.gimp_color_picker(img, layer, j*sample, i*sample, 0,0,0)
        #alphacheck = pdb.gimp_color_picker(img, layer, i*sample, j*sample, 0,0,0)
        if alphacheck[-1] > 0:
            #pdb.gimp_fuzzy_select(layer, i*sample, j*sample, 254.9 , 2,0,0, 0,0)
            pdb.gimp_fuzzy_select(layer, j*sample, i*sample, 254.9 , 2,0,0, 0,0)
            prev_layer = img.active_layer
            newlayer = pdb.gimp_layer_copy( img.active_layer, pdb.gimp_drawable_has_alpha( img.active_layer ) )
            pdb.gimp_image_insert_layer(img, newlayer, None, -1)
            bounds = pdb.gimp_selection_bounds(img)
            pdb.gimp_layer_resize(img.active_layer, bounds[3] - bounds[1], bounds[4] - bounds[2], -bounds[1], -bounds[2])
            img.active_layer = prev_layer
            pdb.gimp_edit_clear(prev_layer)


It works better than your version as it takes into account holes in sprites, but the downside the script is kinda slow.
Further questions:
-How do i make selection go from upper right to lower left in my loop, now it goes diagonally if you know what I mean. The selection went vertically instead of horizontally, i had to switch image.height loop with image.width, very counter intuative.
-How do I rename copied layers to something like <original_layer>### for example layer001, layer002, etc.
Reply


Messages In This Thread
RE: Searching for python script islands to layers - by mich_lloid - 01-22-2018, 10:29 PM

Forum Jump: