# convert a .png image file to a .bmp image file using PIL

from PIL import Image
import glob
import numpy as np

# Convert png to bmp
files = glob.glob('/home/damufo/dev/xesde-client/images/buttons/*.png', recursive=True)
for name in files:
    print(name)
    # img = Image.open(name).convert('RGB')  #.convert('LA')

    # img.save('{}.jpg'.format(name[:-4], optimize=True, format="JPG"))

    #  Load the image and make into Numpy array
    rgba = np.array(Image.open(name))

    # Make image transparent white anywhere it is transparent
    rgba[rgba[...,-1]==0] = [255,255,255,0]

    # Make back into PIL Image and save
    Image.fromarray(rgba).save('{}.bmp'.format(name[:-4]))