|
@@ -12,6 +12,7 @@ from django.views.decorators.clickjacking import xframe_options_sameorigin
|
|
|
from blog import models
|
|
|
from system import settings
|
|
|
from system.error.ServerException import ServerException
|
|
|
+from PIL import Image
|
|
|
|
|
|
|
|
|
@xframe_options_sameorigin
|
|
@@ -23,10 +24,13 @@ def upload_markdown_img(request):
|
|
|
except Exception as e:
|
|
|
return JsonResponse({"errno": 1, "message": str(e)})
|
|
|
from PIL import Image
|
|
|
-
|
|
|
img = Image.open(file_record.file_path + file_record.file_name)
|
|
|
width, height = img.size
|
|
|
- print('Image size: {}x{}'.format(width, height))
|
|
|
+
|
|
|
+ if int(os.path.getsize(file_record.file_path + file_record.file_name) / 1024) > 1024:
|
|
|
+ img.save(file_record.file_path + file_record.file_name, quality=75) # The saved downsized image size is 24.8kb
|
|
|
+ img.close()
|
|
|
+ print('Image size: {}x{}'.format(width, height))
|
|
|
|
|
|
return JsonResponse({"errno": 0, "data": {
|
|
|
'url': file_record.file_net_path,
|
|
@@ -53,7 +57,6 @@ def save_file(file_obj):
|
|
|
filepath = os.path.join(settings.UPLOAD_ROOT + '/' + file_type + '/')
|
|
|
if not os.path.exists(filepath):
|
|
|
os.mkdir(filepath)
|
|
|
-
|
|
|
file_net_path = settings.DOMAIN + settings.UPLOAD_URL + '/' + file_type + '/' + filename
|
|
|
|
|
|
f = open(filepath + filename, 'wb')
|