~bronikowski/onebit

5fd46ca669875a3742f0fe2c2709930c369823ac — Emil Oppeln-Bronikowski 2 years ago
Initial release
3 files changed, 62 insertions(+), 0 deletions(-)

A bitpixel.py
A derp
A test
A  => bitpixel.py +47 -0
@@ 1,47 @@
from PIL import Image
from sys import argv

def detect_size_from_file(filename: str):

    x = None
    y = 0
    with open(filename, 'r') as s:
        lines = s.readlines()

        for line in lines:
            line = line.strip()

            if line == '':
                return (x, y)
            y = y + 1

            if not x:
                x = len(line)
            if x != len(line):
                raise ValueError("Lines are not equal")
        return (x,y)

def set_pixels(image, filename, lightup="*"):
    x = 0
    y = 0
    with open(filename, 'r') as s:
        lines = s.readlines()
        for line in lines:
            for bit in line:
                print(x, y)
                if bit == lightup:
                    image.putpixel((x, y), 255)
                x = x + 1
            y = y + 1
            x = 0
    return image

def create_image(size: list):
    return Image.new("1", size)

if len(argv) == 2:
    xy = detect_size_from_file(argv[1])
    print(xy)
    image = create_image(xy)
    image = set_pixels(image, argv[1])
    image.save('test.png', "PNG")

A  => derp +7 -0
@@ 1,7 @@
...**...
..*..*..
...**...
.******.
...**...
..*..*..
..*..*..

A  => test +8 -0
@@ 1,8 @@
********
*.*.*.*.
.*.*.*.*
*.*.*.*.
.*.*.*.*
*.*.*.*.
.*.*.*.*
********