Created
November 8, 2014 03:40
-
-
Save benawad/fbf9153503a7e0dd527c 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 django.shortcuts import render | |
from django.http import HttpResponse | |
from PIL import Image | |
from converters.forms import UploadForm | |
def index(request): | |
form = UploadForm(request.POST, request.FILES) | |
if form.is_valid(): | |
grey(request.FILES['image']) | |
context = {"form": form} | |
template = "upload.html" | |
return render(request, template, context) | |
def grey(image): | |
img = Image.open(image) | |
size = img.size | |
new_img = Image.new("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) | |
new_img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment