Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. img = Image.open('eggs.png').convert('1')
  2. rawData = img.load()
  3. data = []
  4. for y in range(24):
  5. for x in range(24):
  6. data.append(rawData[x,y])
  7.  
  8. from PIL import Image
  9.  
  10. img = Image.open('eggs.png').convert('L') # convert image to 8-bit grayscale
  11. WIDTH, HEIGHT = img.size
  12.  
  13. data = list(img.getdata()) # convert image data to a list of integers
  14. # convert that to 2D list (list of lists of integers)
  15. data = [data[offset:offset+WIDTH] for offset in range(0, WIDTH*HEIGHT, WIDTH)]
  16.  
  17. # At this point the image's pixels are all in memory and can be accessed
  18. # individually using data[row][col].
  19.  
  20. # For example:
  21. for row in data:
  22. print(' '.join('{:3}'.format(value) for value in row))
  23.  
  24. # Here's another more compact representation.
  25. chars = '@%#*+=-:. ' # Change as desired.
  26. scale = (len(chars)-1)/255.
  27. print()
  28. for row in data:
  29. print(' '.join(chars[int(value*scale)] for value in row))
  30.  
  31. img = Image.open('eggs.png').convert('1')
  32. rawData = img.load()
  33. data = []
  34. for y in range(24):
  35. for x in range(24):
  36. data.append(rawData[x,y][0])
Add Comment
Please, Sign In to add comment