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

33 lines
809 B

4 years ago
#!/usr/bin/env python
import sys
4 years ago
from methods import ascii_bin
4 years ago
method_pointers = {
4 years ago
"ascii_bin": ascii_bin.generate
4 years ago
}
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:
4 years ago
print("Formatting and converting input data...")
4 years ago
inp = get_input(file, bytesize)
method_pointers[method](inp)
if __name__ == "__main__":
4 years ago
try:
generate_image(sys.argv[3], sys.argv[1], int(sys.argv[2]))
except Exception as err:
4 years ago
print("\033[91m./generator.py (method:str) (bytesize:int) (input_file:str)\033[0m")
4 years ago
raise err