Experimental python bmp converter (3-colours to 2-colours)

This commit is contained in:
Ace 2018-09-24 00:11:51 +02:00 committed by GitHub
parent 7b036db3aa
commit 5c6917d202
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

38
experimental Normal file
View file

@ -0,0 +1,38 @@
""" Experimental python script for converting a 3-colour bmp to a 2-colour bmp for use with 2-colour E-Paper displays.
Please use at your own risk.
To use the converter, input a folder path containing the bmps that require converting (input folder)
and then specify an output folder for the converted bmps.
Lastly, replace the original bmp files with the converted ones and reboot to start the E-Paper software with the new bmps.
That's all
Copyright by Ace-Laboratory
"""
import glob, os, errno
from PIL import Image
import PIL.ImageOps
#--------------only change the following two lines-----------------#
path = '/home/pi/Desktop/input/'
path2 = '/home/pi/Desktop/output/'
#-----------------no need to change anything below----------------#
imagenames = []
os.chdir(path) #folder containg files
for files in glob.glob("*.bmp"): #find bmp files
imagenames.append(files) #add these files to a list
print('Found these files:', imagenames) #print this list
print('attempting to convert images to useful ones')
try:
os.makedirs('/home/pi/Desktop/images/converted')
except OSError as e:
if e.errno != errno.EEXIST:
raise
for files in imagenames:
(PIL.ImageOps.posterize(Image.open(path+files), 1).save(path2+files))
print('All done!')
print('You can find your converted files in: ',path2)