add Only Once Function statistic_thumbnail_size to statistic thumbnail size

Brightcells 9 anos atrás
pai
commit
5c9e21b29b
2 arquivos alterados com 26 adições e 1 exclusões
  1. 25 0
      group/views.py
  2. 1 1
      utils/thumbnail_utils.py

+ 25 - 0
group/views.py

@@ -1,5 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
+from __future__ import division
4
+
3 5
 import os
4 6
 import random
5 7
 
@@ -1016,6 +1018,7 @@ class GroupPhotoInfoViewSet(viewsets.ModelViewSet):
1016 1018
 
1017 1019
 # Only Once Function
1018 1020
 def refresh_thumbnail():
1021
+    """ 刷新缩略图 """
1019 1022
     photos = GroupPhotoInfo.objects.filter(status=True)
1020 1023
 
1021 1024
     for photo in photos:
@@ -1052,3 +1055,25 @@ def refresh_thumbnail():
1052 1055
             pass
1053 1056
 
1054 1057
     return 'Refresh Thumbnail OK'
1058
+
1059
+
1060
+def statistic_thumbnail_size():
1061
+    """ 统计缩略图大小 """
1062
+    photos = GroupPhotoInfo.objects.filter(status=True)
1063
+
1064
+    photo_count = photos.count()
1065
+
1066
+    photo_size = 0
1067
+    photo_thumbnail_size = 0
1068
+    photo_thumbnail2_size = 0
1069
+
1070
+    for photo in photos:
1071
+        photo_size += os.path.getsize(os.path.join(settings.MEDIA_ROOT, photo.photo_path).replace('\\', '/'))
1072
+        photo_thumbnail_size += os.path.getsize(os.path.join(settings.MEDIA_ROOT, photo.photo_thumbnail_path).replace('\\', '/'))
1073
+        photo_thumbnail2_size += os.path.getsize(os.path.join(settings.MEDIA_ROOT, photo.photo_thumbnail2_path).replace('\\', '/'))
1074
+
1075
+    print '>>> Photo Size: %.3f KB' % (photo_size / 1024 / photo_count)
1076
+    print '>>> Photo Thumbnail Size: %.3f KB' % (photo_thumbnail_size / 1024 / photo_count)
1077
+    print '>>> Photo Thumbnail2 Size: %.3f KB' % (photo_thumbnail2_size / 1024 / photo_count)
1078
+
1079
+    return 'Statistic Thumbnail Size OK'

+ 1 - 1
utils/thumbnail_utils.py

@@ -15,5 +15,5 @@ def make_thumbnail(im_path, im_thumbnail_path=None, max_width=360):
15 15
     thumb_width = min(max_width, width)
16 16
     thumb_height = height / width * thumb_width
17 17
     im.thumbnail((thumb_width, thumb_height), Image.ANTIALIAS)
18
-    im.save(im_thumbnail_path or im_path, im.format or 'JPEG', quality=100)
18
+    im.save(im_thumbnail_path or im_path, im.format or 'JPEG', quality=90)
19 19
     return width, height, thumb_width, thumb_height