Skip to content

Instantly share code, notes, and snippets.

@DoMINAToR98
Created July 3, 2019 16:33
Show Gist options
  • Save DoMINAToR98/59c3cc9b80e1c733aaf253d94196db76 to your computer and use it in GitHub Desktop.
Save DoMINAToR98/59c3cc9b80e1c733aaf253d94196db76 to your computer and use it in GitHub Desktop.
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