1from PIL import Image
2import os
3
4directory = r'D:\PATH'
5c=1
6for filename in os.listdir(directory):
7 if filename.endswith(".jpg"):
8 im = Image.open(filename)
9 name='img'+str(c)+'.png'
10 rgb_im = im.convert('RGB')
11 rgb_im.save(name)
12 c+=1
13 print(os.path.join(directory, filename))
14 continue
15 else:
16 continue