Skip to content

Instantly share code, notes, and snippets.

@dittos
Last active August 29, 2015 14:17
Show Gist options
  • Save dittos/6a00eaa292d7ccfe220f to your computer and use it in GitHub Desktop.
Save dittos/6a00eaa292d7ccfe220f to your computer and use it in GitHub Desktop.
@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