SHARE
TWEET

emfbadge-imagemaker

a guest Sep 2nd, 2014 276 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PIL import Image
  2. im = Image.open("input.bmp") #Must be monochrome .bmp
  3. im=im.resize((64,128), Image.NEAREST)
  4.  
  5. pix = im.load()
  6. aver=0
  7. for x in range(0,im.size[0]):
  8.  for y in range(0,im.size[1]):
  9.   aver+=pix[x,y]
  10.  
  11. aver= aver/(im.size[0]*im.size[1])
  12.  
  13. #print start of c++ code:
  14. print """static const uint8_t TiLDA_Logo_64x128[] = {
  15.  64, // width
  16.  128, // height
  17. """
  18.  
  19.  
  20. for y in range(0,im.size[1]):
  21.  nextline=""
  22.  nextvalue=0
  23.  for x in range(0,im.size[0]):
  24.   if(x%8==0 and x>0):
  25.    nextline+=str("0x%0.2X" % nextvalue).lower()+","
  26.    nextvalue=0
  27.   if(pix[x,y]>aver):
  28.    nextvalue+=2**(7-(x%8))
  29.  print nextline
  30.  
  31.  
  32. #print end of code:
  33. print "};"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top