Created
November 6, 2013 18:14
-
-
Save Snyder/7341233 to your computer and use it in GitHub Desktop.
Convert a file into it's image representation, it only takes the raw byte stream and make it pixels and then makes an image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import Image | |
from math import sqrt | |
import sys | |
def creaImg(entrada, salida): | |
with open(entrada, 'r') as f: | |
datos = f.read() | |
bytes_datos = bytearray(datos) | |
pixeles = [] | |
x = 0 | |
while (x + 3) < len(bytes_datos): | |
pixeles.append( | |
( | |
bytes_datos[x], | |
bytes_datos[x+1], | |
bytes_datos[x+2] | |
) | |
) | |
x = x + 3 | |
lado = int(sqrt(len(pixeles))) | |
im= Image.new('RGB', (lado, lado)) | |
im.putdata(pixeles[:lado*lado]) | |
im.save(salida) | |
if(len(sys.argv) != 3): | |
print 'Uso: codeToImg.py archivoEntrada imagenSalida' | |
else: | |
creaImg(sys.argv[1],sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment