only crop with 4 crop points

This commit is contained in:
j 2016-02-19 22:29:02 +05:30
parent 1ef547f885
commit 0367816257

View file

@ -225,17 +225,18 @@ class Document(models.Model):
if os.path.exists(src): if os.path.exists(src):
if size and page: if size and page:
crop = map(int, page.split(',')) crop = map(int, page.split(','))
path = os.path.join(folder, '%s.jpg' % ','.join(map(str, crop))) if len(crop) == 4:
if not os.path.exists(path): path = os.path.join(folder, '%s.jpg' % ','.join(map(str, crop)))
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): if not os.path.exists(path):
resize_image(src, path, size=size) 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): if os.path.exists(src) and not os.path.exists(path):
image_size = max(self.width, self.height) image_size = max(self.width, self.height)
if image_size == -1: if image_size == -1: