Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
Command line script that takes a path to an image, grayscales image, and then saves the picture in the directory the original image was found in.
from PIL import Image
import os, shutil
print "Please enter location of image"
input = raw_input('> ')
path = os.path.abspath(input)
img =
size = img.size
new_img ="L", size)
for x in range(0, size[0]):
for y in range(0, size[1]):
loc = (x, y)
pixel = img.getpixel(loc)
val = (pixel[0] + pixel[1] + pixel[2]) / 3
new_img.putpixel(loc, val)
filename = "grey_" + os.path.basename(path)
save_to = os.path.dirname(path)
stored = os.getcwd() + '\\' + filename
shutil.move(stored, save_to)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment