瀏覽代碼

Add crop option to make_thumbnail

version-14
Faris Ansari 7 年之前
父節點
當前提交
bb981536dc
共有 1 個文件被更改,包括 5 次插入2 次删除
  1. +5
    -2
      frappe/core/doctype/file/file.py

+ 5
- 2
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



Loading…
取消
儲存