Just skip files with a extension which isn't PNG, something like:
You can also more directly get the files you need:
Unless I'm mistaken the file_mask is always the same, so this will always yield the same result:
So you can do it once for all, opening the mask as a separate image, that you discard once you have the values.
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.