Skip to content

Instantly share code, notes, and snippets.

@iBaozi
Created October 15, 2015 04:49
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 iBaozi/c76a7ce2e42da3f5f468 to your computer and use it in GitHub Desktop.
Save iBaozi/c76a7ce2e42da3f5f468 to your computer and use it in GitHub Desktop.
__author__ = 'baozi'
import Image,glob,os,colorsys
img_file = '1.jpg'
img_file_new = 'douwa_new.png'
direct = 'h'
z = 1
position1 = {
'x': 327,
'y': 150,
'z': 884
}
position2 = {
'x': 890,
'y': 50,
'z': -78
}
position = {
'x': '~',
'y': '~',
'z': '~'
}
proportion = 0.4
material = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
10: 10,
11: 11,
12: 12,
13: 13,
14: 14,
15: 15,
16: 16
}
material = {
0: 'log',
1: 'dirt',
2: 'planks',
3: 'lapis_block',
4: 'monster_egg',
5: 'emerald_block',
6: 'redstone_block',
7: 'sponge',
8: 'obsidian',
9: 9,
10: 10,
11: 11,
12: 12,
13: 13,
14: 14,
15: 15,
16: 16
}
# .:- + * 8 %
material = {
0 : '.',
1 : ',',
2 : ':',
3 : '-',
4 : '+',
5 : '*',
6 : '8',
7 : '%'
}
def fill(x1, x2, y, id):
id = material[id]
if direct == 'v':
y = -y
params = (x1 + position['x'], z + position['y'], y + position['z'], x2 + position['x'], z + position['y'],
y + position['z'], id)
else:
params = (x1 + position['x'], y + position['y'], z + position['z'], x2 + position['x'], y + position['y'],
z + position['z'], id)
cmd = '/fill %s %s %s %s %s %s %s' % params
return cmd
im = Image.open(img_file)
print im.mode
# 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)
# color
# im = im.quantize(colors=8)
# colors = im.convert('RGBA').getcolors()
# print colors
# print len(colors)
#
# 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, pixels[y][x])
# print output
#cmd
# cmds = ''
# cmds_num = 0
# for y in pixels:
# start = ''
# for x in pixels[y]:
# pixels[y][x] = int(pixels[y][x]/2) #merge
# if start == '':
# start = pixels[y][x]
# elif start != pixels[y][x] or x == size[0]:
# cmds = '%s\r\n%s' % (cmds, fill(start, x, y, pixels[y][x]))
# cmds_num = cmds_num + 1
# start = ''
#
# print cmds
# print '%s cmds' % cmds_num
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
#im = im.resize(size)
#im.save(img_file_new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment