cropped thumbnails of image documents

This commit is contained in:
j 2015-02-05 08:08:28 +00:00
parent ed2c73d732
commit 809486b43c
2 changed files with 17 additions and 2 deletions

View file

@ -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:

View file

@ -30,8 +30,8 @@ urlpatterns = patterns('',
(r'^file/(?P<oshash>.*)$', 'archive.views.lookup_file'),
(r'^api/?$', include(ox.django.api.urls)),
(r'^resetUI$', 'user.views.reset_ui'),
(r'^documents/(?P<id>[A-Z0-9]+)/(?P<size>\d*)p(?P<page>\d*).jpg$', 'document.views.thumbnail'),
(r'^documents/(?P<id>[A-Z0-9]+)/(?P<name>.*?\..+)$', 'document.views.file'),
(r'^documents/(?P<id>[A-Z0-9]+)/(?P<size>\d*)p(?P<page>[\d,]*).jpg$', 'document.views.thumbnail'),
(r'^documents/(?P<id>[A-Z0-9]+)/(?P<name>.*?\.[^\d]{3})$', 'document.views.file'),
(r'^edit/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'edit.views.icon'),
(r'^list/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'itemlist.views.icon'),
(r'^text/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'text.views.icon'),