there:
I got a list of absolute path + file name by using glob.glob() function. However, I try to use split function to extract my file name but I can't find the best way. For example:
first item in my list is: 'C:\Users\xxxxx\Desktop\Python Training\Python Training-Home\Practices\Image Assembly\bird_01.png'. There are several images like bird_02.png...etc. I successfully resized them and tried to re-save them in different location. Please see below for part of my code. My problem statement is I can't find the way to extract "image_filename" in my code. I just need like bird_01, bird_02...etc. Please help me. Thank you in advance.
if not os.path.exists(output_dir):
os.mkdir(output_dir)
for image_file in all_image_files:
print 'Processing', image_file, '...'
img = Image.open(image_file)
width, height = img.size
percent = float((float(basewidth)/float(width)))
hresize = int(float(height) * float(percent))
if width != basewidth:
img = img.resize((basewidth, hresize), Image.ANTIALIAS)
image_filename = image_file.split('_')[0]
image_filename = output_dir + '/' + image_filename
print 'Save to ' + image_filename
img.save(image_filename)