Skip to content

Instantly share code, notes, and snippets.

@sumomoneko
Last active January 13, 2018 12:07
Show Gist options
  • Save sumomoneko/56142201b44ac3dbf1dfe22bedd02323 to your computer and use it in GitHub Desktop.
Save sumomoneko/56142201b44ac3dbf1dfe22bedd02323 to your computer and use it in GitHub Desktop.
画像からいくつかのピクセルを抜き取り平均の色を得る
def getColor():
r = requests.get("http://example.jp/live.jpg")
if r.ok:
image = PIL.Image.open(io.BytesIO(r.content))
# 座標 x,y = (10,10), (100, 10), ..., (600, 20) の平均 r,g,b を得る
return map(statistics.mean,
zip(*(image.getpixel(pos) for pos in itertools.product((10, 100, 200, 300, 400, 500, 600), (10, 20)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment