Skip to content

Instantly share code, notes, and snippets.

@DanBrink91
Created August 25, 2013 02:15
Show Gist options
  • Save DanBrink91/6331541 to your computer and use it in GitHub Desktop.
Save DanBrink91/6331541 to your computer and use it in GitHub Desktop.
reduce the amount of colors in an image
#! /usr/bin/python
import Image
source = Image.open("test.jpg")
img = source.load()
width = source.size[0]
height = source.size[1]
reduction_factor =50 # Higher number means less color
for y in xrange(0, height):
for x in xrange(0, width):
img[x, y] = (img[x,y][0] - (img[x, y][0] % reduction_factor), img[x, y][1] - (img[x, y][1] % reduction_factor), img[x, y][2] - (img[x, y][2] % reduction_factor))
source.save("less3.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment