From bb981536dcdc5f00aa6fe1f50bb58ed381f7d1ba Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 5 Sep 2017 12:12:20 +0530 Subject: [PATCH] Add crop option to make_thumbnail --- frappe/core/doctype/file/file.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index f6f5da3fe6..4341d557aa 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -170,7 +170,7 @@ class File(NestedSet): super(File, self).on_trash() self.delete_file() - def make_thumbnail(self, set_as_thumbnail=True, width=300, height=300, suffix="small"): + def make_thumbnail(self, set_as_thumbnail=True, width=300, height=300, suffix="small", crop=False): if self.file_url: if self.file_url.startswith("/files"): try: @@ -185,7 +185,10 @@ class File(NestedSet): return size = width, height - image.thumbnail(size) + if crop: + image = ImageOps.fit(image, size, Image.ANTIALIAS) + else: + image.thumbnail(size, Image.ANTIALIAS) thumbnail_url = filename + "_" + suffix + "." + extn