Compare commits
No commits in common. "e94a856a081cfe1c59e9288c96a1b5edcba3edca" and "0860f37ac02141a2fdf19923be7fda34ba25974a" have entirely different histories.
e94a856a08
...
0860f37ac0
2 changed files with 5 additions and 24 deletions
|
@ -1,24 +1,11 @@
|
|||
import msgpack
|
||||
import pickle
|
||||
|
||||
from django_redis.serializers.base import BaseSerializer
|
||||
|
||||
|
||||
def default(obj):
|
||||
# Pickle anything that MessagePack can't handle itself.
|
||||
return msgpack.ExtType(69, pickle.dumps(obj, protocol=4))
|
||||
|
||||
|
||||
def ext_hook(code, data):
|
||||
# Unpickle if we pickled - otherwise do nothing.
|
||||
if code == 69:
|
||||
return pickle.loads(data)
|
||||
return msgpack.ExtType(code, data)
|
||||
|
||||
|
||||
class MSGPackModernSerializer(BaseSerializer):
|
||||
def dumps(self, value):
|
||||
return msgpack.packb(value, default=default, use_bin_type=True)
|
||||
return msgpack.packb(value, use_bin_type=True)
|
||||
|
||||
def loads(self, value):
|
||||
return msgpack.unpackb(value, ext_hook=ext_hook, raw=False)
|
||||
return msgpack.unpackb(value, raw=False)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.views.decorators.cache import cache_page
|
||||
from PIL import Image
|
||||
|
||||
from lemoncurry import utils
|
||||
|
@ -13,7 +12,6 @@ def try_libravatar_org(hash, get):
|
|||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
@cache_page(60 * 15)
|
||||
def libravatar(request, hash):
|
||||
g = request.GET
|
||||
size = g.get('s', g.get('size', 80))
|
||||
|
@ -44,12 +42,8 @@ def libravatar(request, hash):
|
|||
return try_libravatar_org(hash, g)
|
||||
|
||||
im = Image.open(user.avatar)
|
||||
image_type = im.format
|
||||
natural_size = min(im.size)
|
||||
im_resized = im.resize((size, size))
|
||||
|
||||
im = im.crop((0, 0, natural_size, natural_size))
|
||||
im = im.resize((size, size), resample=Image.HAMMING)
|
||||
|
||||
response = HttpResponse(content_type='image/'+image_type.lower())
|
||||
im.save(response, image_type)
|
||||
response = HttpResponse(content_type='image/'+im.format.lower())
|
||||
im_resized.save(response, im.format)
|
||||
return response
|
||||
|
|
Loading…
Reference in a new issue