Skip to content

Instantly share code, notes, and snippets.

@koma5
Created December 13, 2016 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koma5/f9592ed678c2ff8568f314b09af46b3c to your computer and use it in GitHub Desktop.
Save koma5/f9592ed678c2ff8568f314b09af46b3c to your computer and use it in GitHub Desktop.
create a grayscale picture of magnet links
#!/usr/bin/python
import Image, sys, random
hash = random.choice(['411A7A164505636AB1A8276395B375A3A30BFF32',
'79816060EA56D56F2A2148CD45705511079F9BCA',
'f5615dfb80ac995787c1b2219a75df7805278dea',
'43b21801f59336b9271a6c5113904fb72de99ed3',
'938802790a385c49307f34cca4c30f80b03df59c'])
if(len(sys.argv) == 4):
hash = sys.argv[1]
width = int(sys.argv[2])
height= int(sys.argv[3])
elif((len(sys.argv) == 3)):
width = int(sys.argv[1])
height= int(sys.argv[2])
else:
width = 20
height= 1
n = 2
chunked = [ int(hash[i:i+n], 16) for i in range(0, len(hash), n) ]
print hash
print [hex(c) for c in chunked]
print chunked
# https://infohost.nmt.edu/tcc/help/pubs/pil/defs.html#mode
# "L" 8-bit Grayscale
img = Image.new("RGB", (width, height))
pixel = img.load()
i = 0
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
pixel[x,y] = (chunked[i], chunked[i], chunked[i])
i += 1
# 500% resize
# img = img.resize((width*5, height*5), Image.NEAREST) #not preserving hard edges
img.save("hashPic.png", "PNG")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment