Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whitlisting file inputs
#2
Just skip files with a extension which isn't PNG, something like:

Code:
filename,fileext = os.path.splitext(element) # replaces a line of yours
if fileext[1:].upper() != 'PNG':
   continue

You can also more directly get the files you need:

Code:
import glob
files=glob.glob(os.path.join(file_inpath,'*.png')  # elements have their full paths

Unless I'm mistaken the file_mask is always the same, so this will always yield the same result:

Code:
# Add mask to new layer over image
layer_mask = pdb.gimp_file_load_layer(image,file_mask)
pdb.gimp_image_insert_layer(image,layer_mask,None,0)

# Mask layer alpha to selection
pdb.gimp_image_select_item(image,2,pdb.gimp_image_get_active_layer(image))
pdb.gimp_image_remove_layer(image,layer_mask)

# Invert Selection
pdb.gimp_selection_invert(image)

# Crop to selection
dimensions = pdb.gimp_selection_bounds(image)

So you can do it once for all, opening the mask as a separate image, that you discard once you have the values.
Reply


Messages In This Thread
Whitlisting file inputs - by radzo73 - 12-22-2019, 03:43 PM
RE: Whitlisting file inputs - by Ofnuts - 12-22-2019, 04:53 PM
RE: Whitlisting file inputs - by radzo73 - 12-22-2019, 07:06 PM

Forum Jump: