User:Mths/rgb sort: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
[[File: | [[File:Lastf.jpg| 400px]] [[File:Rgb_loop.gif]] | ||
[[File: | |||
<source lang="python"> | <source lang="python"> |
Latest revision as of 19:19, 1 April 2013
from PIL import Image, ImageDraw
import sys
filename = sys.argv[1]
newfilename = sys.argv[2]
im = Image.open(filename)
colors = im.getcolors(im.size[0] * im.size[1])
pixels = []
for i, color in colors:
pixels.extend(i * [color])
def inputselect():
sortinput = int(sys.argv[3])
if sortinput == 0:
pixels.sort(key=lambda x: x[0])
print sortinput
elif sortinput == 1:
pixels.sort(key=lambda x: x[1])
print sortinput
elif sortinput == 2:
pixels.sort(key=lambda x: x[2])
print sortinput
try:
inputselect()
except IndexError:
pixels.sort()
print 'sorting...'
im2 = Image.new(im.mode, im.size)
im2.putdata(pixels)
im2.save(newfilename)