getcolors.py 859 B

123456789101112131415161718192021222324252627282930313233343536
  1. import os.path
  2. import requests
  3. from PIL import Image
  4. from collections import defaultdict
  5. filename = 'msquares_color.png'
  6. if not os.path.exists(filename):
  7. baseurl = 'https://prideout.net/assets/'
  8. url = baseurl + filename
  9. r = requests.get(url, stream=True)
  10. with open(filename, 'wb') as fd:
  11. for chunk in r.iter_content():
  12. fd.write(chunk)
  13. im = Image.open(filename)
  14. im.split()[3].save('alpha.png')
  15. Image.merge('RGB', im.split()[0:3]).save('rgb.png')
  16. cols = defaultdict(set)
  17. for pixel in im.getdata():
  18. r, g, b, a = pixel
  19. argb = '%0.2x%0.2x%0.2x%0.2x' % (a, r, g, b)
  20. cols[a].add(argb)
  21. alphas = cols.keys()
  22. alphas.sort()
  23. final = []
  24. for alpha in alphas:
  25. for col in cols[alpha]:
  26. final.append(col)
  27. x = 0
  28. for col in final:
  29. print '0x' + col + ',',
  30. x = x + 1
  31. if x == 5:
  32. print
  33. x = 0