Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from PIL import Image
import binascii
import string
def rgb2hex(r,g,b):
hex = "#{:02x}{:02x}{:02x}".format(r,g,b)
return str(hex)
im = Image.open('bojack.png')
print im
arr=''
pix_val = list(im.getdata())
for idx,val in enumerate(pix_val):
# print rgb2hex(val[0],val[1],val[2])
if(rgb2hex(val[0],val[1],val[2])=="#078401"):
arr+='0';
else:
arr+='1';
# print arr
n = int(arr, 2)
f = open("bo.jpeg", "w") #writing as output
f.write(binascii.unhexlify('%x' % n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment