master
E. Almqvist 4 years ago
commit 2e472a6f86
  1. 2
      .gitignore
  2. 2
      README.md
  3. 23
      ascii_bin.py
  4. 27
      generator.py
  5. 1
      testbytes.txt

2
.gitignore vendored

@ -0,0 +1,2 @@
*.py[cod]
documentation/

@ -0,0 +1,2 @@
# Image Encoder
Script to create images from bytes

@ -0,0 +1,23 @@
import numpy as np
import scipy.misc as smp
bit_on = [255, 255, 255] # RGB value if bit is 1
bit_off = [0, 0, 0] # RGB value if bit is 0
def translate_bit_color(bit:str):
if( bit == "1" ):
return bit_on
else:
return bit_off
def data_to_matrix(data:list) -> np.array:
newdat = [ [translate_bit_color(bit) for bit in byte] for byte in data ]
col_array = np.array(newdat, dtype=np.uint8)
return col_array
def main(inp:list) -> None:
col_array = data_to_matrix(inp)
img = smp.toimage(col_array)
img.show()

@ -0,0 +1,27 @@
#!/usr/bin/env python
import sys
from ascii_bin import main as ascii_bin
method_pointers = {
"ascii_bin": ascii_bin
}
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:
inp = get_input(file, bytesize)
method_pointers[method](inp)
if __name__ == "__main__":
generate_image(sys.argv[3], sys.argv[1], int(sys.argv[2]))

@ -0,0 +1 @@
01100100 01010111 01100100 01101110 01011001 01111010 01101111 01110110 01001100 00110010 00110101 00110101 01100101 01101101 01100100 01111001 01100011 01001000 01010101 01110101 01011010 01101110 01001001 01001011
Loading…
Cancel
Save