Skip to content

Instantly share code, notes, and snippets.

@sjrmanning
Created June 11, 2014 03:45
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 sjrmanning/31ca36338a76bdcd6a4a to your computer and use it in GitHub Desktop.
Save sjrmanning/31ca36338a76bdcd6a4a to your computer and use it in GitHub Desktop.
from PIL import Image
import sys
def main(argv):
input_file = ''
try:
input_file = argv[0]
except:
print 'usage: iconify.py <inputfile>'
sys.exit(2)
iconify(input_file)
def iconify(file):
image = Image.open(file).convert('LA')
pixels = image.load()
width = image.size[0]
height = image.size[1]
icon_string = ''
for y in xrange(0, height):
icon_string += '('
for x in xrange(0, width):
pixel_value = pixels[x,y][0]
pixel_value = 1 - (pixel_value / 255.0)
icon_string += ' '
icon_string += str(pixel_value)
icon_string += ')\n'
print(icon_string)
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment