X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..639546a46a3a3ec9177a3c95e7639b636bb24879:/src/cover/views.py diff --git a/src/cover/views.py b/src/cover/views.py index 3f2c46fa..b1261e6d 100644 --- a/src/cover/views.py +++ b/src/cover/views.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -37,17 +35,30 @@ def preview(request, book, chunk=None, rev=None): else: revision = chunk.publishable() if revision is None: - raise Http404 + revision = chunk.head xml = revision.materialize().encode('utf-8') try: info = BookInfo.from_bytes(xml) except: return HttpResponseRedirect(os.path.join(settings.STATIC_URL, "img/sample_cover.png")) - cover = make_cover(info) + width = request.GET.get('width') + width = int(width) if width else None + height=request.GET.get('height') + height = int(height) if height else None + cover = make_cover(info, width=width, height=height) + #cover = make_cover(info) response = HttpResponse(content_type=cover.mime_type()) - img = cover.image().resize(PREVIEW_SIZE, Image.ANTIALIAS) + if height or width: + size = (width, height) + else: + size = PREVIEW_SIZE + img = cover.image().resize(size, Image.ANTIALIAS) img.save(response, cover.format) + + if 'download' in request.GET: + response['Content-Disposition'] = 'attachment; filename=%s.jpg' % chunk.book.slug + return response