Created
February 28, 2016 02:50
-
-
Save ddworken/334de7cd632c22374715 to your computer and use it in GitHub Desktop.
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
from PIL import Image | |
def average(filename): | |
colorOutput = {'r':-1, 'b':-1, 'g':-1} | |
image = Image.open(filename) | |
for channel in range(3): | |
channelPixels = [pixel for pixel in image.getdata(band=channel)] | |
colorOutput[colorOutput.keys()[channel]] = sum(channelPixels) / len(channelPixels) | |
return colorOutput | |
def median(filename): | |
colorOutput = {'r':-1, 'b':-1, 'g':-1} | |
image = Image.open(filename) | |
medianPixel = max(image.getcolors(image.size[0]*image.size[1])) | |
for channel in range(3): | |
colorOutput[colorOutput.keys()[channel]] = medianPixel[1][channel] | |
return colorOutput | |
def genJS(colorOutput): | |
return """document.body.style.backgroundColor = 'rgb("""+str(colorOutput['r'])+""","""+str(colorOutput['b'])+""","""+str(colorOutput['g'])+""")';""" | |
print genJS(average('/home/david/Downloads/tree.png')) | |
print genJS(median('/home/david/Downloads/tree.png')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment