Have to use command line tool Image Magick.
>>> import subprocess
>>> subprocess.check_call(['convert', 'oxygen.png', 'oxy.txt'])
0
Read in the Image Magick text file.
>>> with open('oxy.txt') as f:
... lines = f.readlines()
...
Parse file header.
>>> m = re.match(r'# ImageMagick pixel enumeration:\s*?(\d+),(\d+),.*', lines.pop(0))
>>> w, h = [int(g) for g in m.groups()]
>>>
>>> print('Dims: ', w, 'x', h)
Dims: 629 x 95
Read in pixel data.
>>>
>>> p = re.compile(r'(\d+),(\d+): \(\s*?(\d+),\s*?(\d+),\s*?(\d+),.*')
>>> pixdata = []
>>> for i in range(h):
... pixdata.append([0] * w)
... for j in range(w):
... m = p.match(lines[i * w + j])
... x, y, r, g, b = [int(g) for g in m.groups()]
... pixdata[i][j] = (r, g, b)
...
>>> s = ''.join(chr(pixdata[48][j][0]) for j in range(0, 608, 7))
>>> print(s)
smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
>>> print(''.join(chr(int(n)) for n in s[43:-1].replace(',', '').split()))
integrity
No comments:
Post a Comment