From 4de5aaf806d7667e2a9186f23e6b58f9c9309e9f Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 3 Oct 2018 02:01:37 +0200 Subject: [PATCH] Deprecated, replaced by 2-Colour converter --- For-developers-only/image-converter-alpha | 68 ----------------------- 1 file changed, 68 deletions(-) delete mode 100644 For-developers-only/image-converter-alpha diff --git a/For-developers-only/image-converter-alpha b/For-developers-only/image-converter-alpha deleted file mode 100644 index 6a9dd6e..0000000 --- a/For-developers-only/image-converter-alpha +++ /dev/null @@ -1,68 +0,0 @@ -""" -Experimental converter that transforms standard png, jpg and bmp files to useable bmp files which can be used by the Calendar. -# Currently in ALPHA mode. Please use with caution and keep backups -# Version 1.0 (initial) - -# Copyright by Ace-Laboratory -""" - -## What this script does: -# grab images from one folder, perform some operations and paste them in an output folder. -# The operations consists of removing the alpha channel, reducing the colours to (currently) just two, -# Inverting the colours (as the display inverts them again) and rotating the picture by 90 deg clockwise - -## Please only use png files for now as that has been tested and confirmed to work so far. - -import glob, os, errno -from PIL import Image -import PIL.ImageOps -#--------------only change the following two lines-----------------# -input_folder = '/home/pi/input/' -output_folder = '/home/pi/output/' -#-----------------no need to change anything below----------------# - -os.chdir(input_folder) - -pngs = [] -for files in glob.glob("*.png"): - pngs.append(os.path.splitext(os.path.basename(files))[0]) - -bmps = [] -for files in glob.glob("*.bmp"): - bmps.append(files) - -jpegs= [] -for files in glob.glob("*.jpg"): - print(os.path.splitext(os.path.basename(files))[0]) - jpegs.append(os.path.splitext(os.path.basename(files))[0]) - -print('converting...') - -thresh = 126 # any value below 127 works. -fn = lambda x : 255 if x > thresh else 0 - -# PNG to BMP conversion -for files in pngs: #part1: first from png to bmp - png=Image.open(input_folder+files+".png") - png.load() - background = Image.new("RGB", png.size, (255, 255, 255)) - background.paste(png, mask=png.split()[3]) - background.convert('L').point(fn, mode='1').save((output_folder+files+'.bmp'), 'BMP', quality=90) - -png_bmp = [] #part2: and then from bmp to bmp -os.chdir(output_folder) -for files in glob.glob("*.bmp"): - png_bmp.append(files) -for files in png_bmp: - (PIL.ImageOps.invert((Image.open(output_folder+files).rotate(-90, expand=True)).convert('L'))).save(output_folder+files) - -# BMP to BMP conversion -for files in bmps: - (PIL.ImageOps.invert((Image.open(input_folder+files).rotate(-90, expand=True)).convert('L'))).save(output_folder+files) - -# JPG to BMP (do not use) -for files in jpegs: - (Image.open(input_folder+files+".jpg").convert('L').save(output_folder+files+".bmp")) -print('All done') - -