From 809486b43c96b9254c40c6e9424ea99392f06fc3 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 5 Feb 2015 08:08:28 +0000 Subject: [PATCH] cropped thumbnails of image documents --- pandora/document/models.py | 15 +++++++++++++++ pandora/urls.py | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pandora/document/models.py b/pandora/document/models.py index a1102717..5a014385 100644 --- a/pandora/document/models.py +++ b/pandora/document/models.py @@ -216,6 +216,21 @@ class Document(models.Model): self.extract_page(page) if size: path = os.path.join(folder, '%dp%d.jpg' % (size, page)) + elif self.extension in ('jpg', 'png', 'gif'): + if os.path.exists(src): + if size and page: + crop = map(int, page.split(',')) + path = os.path.join(folder, '%s.jpg' % ','.join(map(str, crop))) + if not os.path.exists(path): + img = Image.open(src).crop(crop) + img.save(path) + else: + img = Image.open(path) + src = path + if size < max(img.size): + path = os.path.join(folder, '%sp%s.jpg' % (size, ','.join(map(str, crop)))) + if not os.path.exists(path): + resize_image(src, path, size=size) if os.path.exists(src) and not os.path.exists(path): image_size = max(self.width, self.height) if image_size == -1: diff --git a/pandora/urls.py b/pandora/urls.py index 19162a73..00b0b14f 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -30,8 +30,8 @@ urlpatterns = patterns('', (r'^file/(?P.*)$', 'archive.views.lookup_file'), (r'^api/?$', include(ox.django.api.urls)), (r'^resetUI$', 'user.views.reset_ui'), - (r'^documents/(?P[A-Z0-9]+)/(?P\d*)p(?P\d*).jpg$', 'document.views.thumbnail'), - (r'^documents/(?P[A-Z0-9]+)/(?P.*?\..+)$', 'document.views.file'), + (r'^documents/(?P[A-Z0-9]+)/(?P\d*)p(?P[\d,]*).jpg$', 'document.views.thumbnail'), + (r'^documents/(?P[A-Z0-9]+)/(?P.*?\.[^\d]{3})$', 'document.views.file'), (r'^edit/(?P.*?)/icon(?P\d*).jpg$', 'edit.views.icon'), (r'^list/(?P.*?)/icon(?P\d*).jpg$', 'itemlist.views.icon'), (r'^text/(?P.*?)/icon(?P\d*).jpg$', 'text.views.icon'),