Skip to content

Instantly share code, notes, and snippets.

@dittos dittos/c60.py
Last active Aug 29, 2015

Embed
What would you like to do?
@Code_60: Sorting
import sys
from wand.image import Image
from wand.color import Color
from wand.drawing import Drawing
with Image(filename=sys.argv[1]) as img:
pixels = []
for row in img:
for col in row:
pixels.append(col)
print 'sorting'
pixels.sort()
print 'drawing'
with Drawing() as draw:
for ix, c in enumerate(pixels):
draw.fill_color = c
draw.point(ix % img.width, ix // img.width)
if ix % 100000 == 0: print ix
print 'saving'
with Color('white') as bg:
with Image(width=img.width, height=img.height, background=bg) as i:
draw(i)
i.save(filename='result.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.