Simple script to list all files in a files in a directory
*This assumes all files in folder are png images.
import os
from PIL import Image
image_path = '../tmp/'
image_path_jpg = image_path + 'jpg/'
images = [f for f in os.listdir(image_path) if os.path.isfile(os.path.join(image_path, f))]
for file in images:
im = Image.open(image_path + file)
if im.mode == 'RGBA':
background = Image.new(im.mode[:-1], im.size, '#ffffff')
background.paste(im, im.split()[-1])
background.save(image_path_jpg + os.path.splitext(os.path.basename(file))[0] + '.jpg')
else:
im = im.convert('RGB')
im.save(image_path_jpg + os.path.splitext(os.path.basename(file))[0] + '.jpg')
can change to this if you want to be more specific with the file listing.