Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from PIL import Image
import sys
from re import sub
import base64
if len(sys.argv) != 3:
print "usage: ./ [in_img] [in_data] saves to out.png"
f = open(sys.argv[2])
d_clear =
def encode(text):
return sub(r'(.)\1*', lambda m: str(len( +,text)
print " eat my balls -> %s " % encode("eat my balls")
print " aaaaabbbbb -> %s" % encode("aaaaabbbbb")
d = encode(d_clear)
o = ""
for c in d:
o += bin(ord(c))[2:].rjust(8,'0')
o_a = [o[n:n+2] for n in range(0,len(o),2)]
in_img =[1])
in_pixels = in_img.convert("RGB")
in_l = in_img.load()
width, height = in_img.size
if len(o_a) > width * height:
print "error: not enough canvas to paint with"
for i in range(0,len(o_a)):
temp_x = i % width
temp_y = i / width
(r,g,b) = in_pixels.getpixel((temp_x,temp_y))
new_r = int(bin(r)[2:8] + o_a[i],2)
in_l[temp_x,temp_y] = (new_r,g,b)
print "finish: wrote %d times" % len(o_a)"out.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.