Update beta-converter.py
This commit is contained in:
parent
05cac6ad58
commit
572dd170db
@ -12,34 +12,39 @@ backup of the entire 'Calendar" folder first.
|
||||
|
||||
Copyright by Ace-Laboratory
|
||||
"""
|
||||
# Usage:
|
||||
# 1) Downlaod this file and copy the downloaded file to the raspberry (via VNC or WinSCP)
|
||||
# 2) Execute the file without any modifications
|
||||
# 3) In the section just below, change 'other/' to 'months/' and then execute again. Reboot and you're done.
|
||||
|
||||
#--------------only change the following two lines-----------------#
|
||||
input_path = '/home/pi/E-Paper-Master/Calendar/other/'
|
||||
output_path = '/home/pi/E-Paper-Master/Calendar/other/'
|
||||
#-----------------no need to change anything below-----------------#
|
||||
|
||||
"""
|
||||
Info: These path contain the bmps that require converting.
|
||||
1) /home/pi/E-Paper-Master/Calendar/months/
|
||||
3) /home/pi/E-Paper-Master/Calendar/other/
|
||||
"""
|
||||
|
||||
path = '/home/pi/E-Paper-Master/Calendar/'
|
||||
#--------------only change the following two lines-----------------#
|
||||
input_path_1 = path+'other/'
|
||||
output_path_1 = path+'other/'
|
||||
input_path_2 = path+'months/'
|
||||
output_path_2 = path+'months/'
|
||||
#-----------------no need to change anything below-----------------#
|
||||
|
||||
import glob, os, errno
|
||||
from PIL import Image
|
||||
import PIL.ImageOps
|
||||
|
||||
imagenames = []
|
||||
imagenames_1 = []
|
||||
imagenames_2 = []
|
||||
|
||||
print('opening the specified directory...')
|
||||
|
||||
os.chdir(input_path) #folder containg files
|
||||
os.chdir(input_path_1) #folder containg files
|
||||
for files in glob.glob('*.bmp'): #find bmp files
|
||||
imagenames.append(files) #add these files to a list
|
||||
imagenames_1.append(files) #add these files to a list
|
||||
print('Found these files:', imagenames_1) #print this list
|
||||
|
||||
print('Found these files:', imagenames) #print this list
|
||||
os.chdir(input_path_2) #folder containg files
|
||||
for files in glob.glob('*.bmp'): #find bmp files
|
||||
imagenames_2.append(files) #add these files to a list
|
||||
print('Found these files:', imagenames_2) #print this list
|
||||
|
||||
# 0 is black, 255 is white, 127 is red.
|
||||
# The following will convert the 'red' parts to white parts.
|
||||
@ -47,17 +52,28 @@ thresh = 100 # any value below 127 works.
|
||||
fn = lambda x : 255 if x > thresh else 0
|
||||
|
||||
try:
|
||||
print('checking if the output path exists...')
|
||||
os.makedirs(output_path)
|
||||
print('checking if the first output path exists...')
|
||||
os.makedirs(output_path_1)
|
||||
except OSError as e:
|
||||
print('Oh, the output path exists already. Assuming you know what you are doing.')
|
||||
print('Oh, the first output path exists already. Assuming you know what you are doing.')
|
||||
print('Will attempt to overwrite all .bmp files')
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
|
||||
try:
|
||||
print('checking if the second output path exists...')
|
||||
os.makedirs(output_path_2)
|
||||
except OSError as e:
|
||||
print('Oh, the second output path exists already. Assuming you know what you are doing.')
|
||||
print('Will attempt to overwrite all .bmp files')
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
print('attempting to convert images...')
|
||||
for files in imagenames:
|
||||
((Image.open(input_path+files)).convert('L').point(fn, mode='1').save(output_path+files))
|
||||
for files in imagenames_1:
|
||||
((Image.open(input_path_1+files)).convert('L').point(fn, mode='1').save(output_path_1+files))
|
||||
for files in imagenames_2:
|
||||
((Image.open(input_path_2+files)).convert('L').point(fn, mode='1').save(output_path_2+files))
|
||||
|
||||
print('All done!')
|
||||
print('You can find your converted files in: ',output_path)
|
||||
print('The bmp have been converted. Good luck!')
|
||||
|
Loading…
Reference in New Issue
Block a user