Skip to content

Instantly share code, notes, and snippets.

@lunaluxie
Created February 13, 2017 12:18
Show Gist options
  • Save lunaluxie/e2c20e3187de7b72912f252f3e9c610a to your computer and use it in GitHub Desktop.
Save lunaluxie/e2c20e3187de7b72912f252f3e9c610a to your computer and use it in GitHub Desktop.
from PIL import Image
import numpy as np
img = Image.open('img.jpg', "r")
pixels = np.asarray(img)
add = [0,0,0]
index = 0
for row in pixels:
for pixel in row:
add += pixel
index += 1
result = add/index
result_list = []
for x in result:
result_list.append(int(round(x)))
print ('#%02x%02x%02x' % tuple(result_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment