Skip to content

Instantly share code, notes, and snippets.

@iBaozi
Created October 15, 2015 05:00
Show Gist options
  • Save iBaozi/38561e79cac5bf5ee6a8 to your computer and use it in GitHub Desktop.
Save iBaozi/38561e79cac5bf5ee6a8 to your computer and use it in GitHub Desktop.
__author__ = 'baozi'
import Image
img_file = '1.jpg'
proportion = 0.3
# .:- + * 8 %
material = {
0 : '.',
1 : ',',
2 : ':',
3 : '-',
4 : '+',
5 : '*',
6 : '8',
7 : '%'
}
im = Image.open(img_file)
# Pixel
size = im.size
print size
size_new = (int(size[0] * proportion), int(size[1] * proportion))
print size_new
im = im.resize(size_new)
im = im.convert('L').quantize(colors=8)
pixels = {}
for y in range(1, size_new[1]):
pixels[y] = {}
output = ''
for x in range(1, size_new[0]):
pixels[y][x] = im.getpixel((x, y))
output = '%s %s' % (output, material[pixels[y][x]])
print output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment