Last active
August 29, 2015 14:17
-
-
Save dittos/6a00eaa292d7ccfe220f to your computer and use it in GitHub Desktop.
@Code_60: Sorting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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