Whee, good night.
parent
9d3e9bd248
commit
0dd51262f2
|
@ -27,20 +27,22 @@ def select_best_pope(aspect_ratio):
|
|||
r_lte = abs(aspect_ratio - lte[0].aspect_ratio)
|
||||
r_gte = abs(aspect_ratio - gte[0].aspect_ratio)
|
||||
if r_lte >= r_gte:
|
||||
pp = PerfectPope(aspect_ratio=aspect_ratio, pope=gte[0]).save()
|
||||
return gte[0].path
|
||||
return _select_pope(aspect_ratio, gte[0])
|
||||
else:
|
||||
pp = PerfectPope(aspect_ratio=aspect_ratio, pope=lte[0]).save()
|
||||
return lte[0].path
|
||||
return _select_pope(aspect_ratio, lte[0])
|
||||
|
||||
|
||||
def _select_pope(aspect_ratio, pope):
|
||||
pp = PerfectPope(aspect_ratio=aspect_ratio, pope=pope)
|
||||
pp.save()
|
||||
return pope.path
|
||||
|
||||
|
||||
|
||||
class PopeMaster:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def parse_popes(self):
|
||||
self.parse_pope("papiez.jpg")
|
||||
|
||||
def parse_pope(self, pope):
|
||||
im = Image.open(pope)
|
||||
width, height = im.size
|
||||
|
|
|
@ -3,7 +3,7 @@ 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
|
||||
from papiezator.pope_utils import select_best_pope, ENOPopeException
|
||||
|
||||
|
||||
def index(request):
|
||||
|
@ -16,11 +16,14 @@ 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)
|
||||
try:
|
||||
pope = select_best_pope(aspect_ratio)
|
||||
except ENOPopeException:
|
||||
return("czarny dym")
|
||||
|
||||
im = Image.open(pope)
|
||||
im = im.resize((width, height))
|
||||
f = BytesIO()
|
||||
f = BytesIO() # FIXME: ceriously.
|
||||
im.save(f, "jpeg")
|
||||
f.seek(0)
|
||||
return HttpResponse(f.read(), mimetype="image/jpeg")
|
||||
|
|
Loading…
Reference in New Issue