Generate images via specialized methods.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
imageencoder/generator.py

32 lines
809 B

#!/usr/bin/env python
import sys
from methods import ascii_bin
method_pointers = {
"ascii_bin": ascii_bin.generate
}
def get_input(file:str, bytesize:int = 8) -> list:
f = open(file, "r")
f_str = f.read()
f_str = f_str.strip()
f_str = f_str.replace(" ", "")
return [ f_str[i:i+bytesize] for i in range(0, len(f_str), bytesize) ]
def generate_image(file:str, method:str = "ascii_bin", bytesize:int = 8) -> None:
print("Formatting and converting input data...")
inp = get_input(file, bytesize)
method_pointers[method](inp)
if __name__ == "__main__":
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) (input_file:str)\033[0m")
raise err