diff --git a/ascii_bin-image.jpg b/ascii_bin-image.jpg new file mode 100644 index 0000000..996b849 Binary files /dev/null and b/ascii_bin-image.jpg differ diff --git a/ascii_bin.py b/ascii_bin.py index 0bcebfd..5f79023 100644 --- a/ascii_bin.py +++ b/ascii_bin.py @@ -1,5 +1,7 @@ import numpy as np import scipy.misc as smp +from PIL import Image + bit_on = [255, 255, 255] # RGB value if bit is 1 bit_off = [0, 0, 0] # RGB value if bit is 0 @@ -16,8 +18,8 @@ def data_to_matrix(data:list) -> np.array: return col_array -def main(inp:list) -> None: +def generate(inp:list) -> None: col_array = data_to_matrix(inp) - img = smp.toimage(col_array) - img.show() + img = Image.fromarray(col_array, "RGB") + img.save("ascii_bin-image.jpg") diff --git a/generator.py b/generator.py index 8cec4d7..653dfde 100755 --- a/generator.py +++ b/generator.py @@ -1,10 +1,10 @@ #!/usr/bin/env python import sys -from ascii_bin import main as ascii_bin +import ascii_bin method_pointers = { - "ascii_bin": ascii_bin + "ascii_bin": ascii_bin.generate } @@ -24,4 +24,8 @@ def generate_image(file:str, method:str = "ascii_bin", bytesize:int = 8) -> None if __name__ == "__main__": - generate_image(sys.argv[3], sys.argv[1], int(sys.argv[2])) + try: + generate_image(sys.argv[3], sys.argv[1], int(sys.argv[2])) + except Exception as err: + print("\033[91m./generator.py (method:str) (bytesize:int) (dimensions:str (WxH)) (input_file:str)\033[0m") + raise err