#!/usr/bin/env python # -*- encoding: utf-8 -*- from papiezator.pope_utils import get_pope, redis_me, http_return_image from django.http import HttpResponse from io import BytesIO from PIL import Image # FIXME: kind of fugly. @redis_me def get_noir_pope(width, height, pope_id): pope_buffer = BytesIO() pope = get_pope(width, height, pope_id) if not pope: return None pope = Image.open(BytesIO(pope)).convert("L") pope.save(pope_buffer, "jpeg") pope = pope_buffer pope.seek(0) return pope.read() @http_return_image def view(request, width, height, pope_id=0): width, height = int(width), int(height) pope = get_noir_pope(width, height, pope_id) return pope