crop pdf pages
This commit is contained in:
parent
14e197819d
commit
eaad9badbb
1 changed files with 19 additions and 1 deletions
|
@ -522,7 +522,13 @@ class Document(models.Model, FulltextMixin):
|
||||||
else:
|
else:
|
||||||
path = src
|
path = src
|
||||||
if self.extension == 'pdf':
|
if self.extension == 'pdf':
|
||||||
|
crop = []
|
||||||
if page:
|
if page:
|
||||||
|
if ',' in page:
|
||||||
|
crop = list(map(int, page.split(',')))
|
||||||
|
page = crop[0]
|
||||||
|
crop = crop[1:]
|
||||||
|
else:
|
||||||
page = int(page)
|
page = int(page)
|
||||||
if page and page > 1 and page <= self.pages:
|
if page and page > 1 and page <= self.pages:
|
||||||
src = os.path.join(folder, '1024p%d.jpg' % page)
|
src = os.path.join(folder, '1024p%d.jpg' % page)
|
||||||
|
@ -533,6 +539,18 @@ class Document(models.Model, FulltextMixin):
|
||||||
self.extract_page(page)
|
self.extract_page(page)
|
||||||
if size:
|
if size:
|
||||||
path = os.path.join(folder, '%dp%d.jpg' % (size, page))
|
path = os.path.join(folder, '%dp%d.jpg' % (size, page))
|
||||||
|
if len(crop) == 4:
|
||||||
|
path = os.path.join(folder, '%dp%d,%s.jpg' % (1024, page, ','.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, '%dp%d,%s.jpg' % (size, page, ','.join(map(str, crop)))
|
||||||
|
if not os.path.exists(path):
|
||||||
|
resize_image(src, path, size=size)
|
||||||
elif self.extension in ('jpg', 'png', 'gif'):
|
elif self.extension in ('jpg', 'png', 'gif'):
|
||||||
if os.path.exists(src):
|
if os.path.exists(src):
|
||||||
if size and page:
|
if size and page:
|
||||||
|
|
Loading…
Reference in a new issue