papiez_ipsum/papiezator/views.py

29 lines
749 B
Python

# Create your views here.
from django.shortcuts import render
from django.http import HttpResponse
from PIL import Image
from io import BytesIO # FIXME:
from papiezator.pope_utils import select_best_pope
def index(request):
return render(request,
"papiezator/index.html")
pass
def conclave(request, width, height):
width, height = int(width), int(height)
if width > 0 and height > 0:
aspect_ratio = width/height
pope = select_best_pope(aspect_ratio)
im = Image.open(pope)
im = im.resize((width, height))
f = BytesIO()
im.save(f, "jpeg")
f.seek(0)
return HttpResponse(f.read(), mimetype="image/jpeg")
else:
return HttpResponse("8====D~~~~")