| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | # -*- coding: utf-8 -*- | 
| 2 | 2 |  | 
| 3 | +from django.conf import settings | |
| 3 | 4 | from django.core.files.storage import default_storage | 
| 4 | 5 | from django.db import transaction | 
| 5 | 6 | from django.http import JsonResponse | 
| @@ -10,6 +11,7 @@ from account.models import UserInfo | ||
| 10 | 11 | from group.models import GroupInfo, GroupUserInfo, GroupPhotoInfo | 
| 11 | 12 | from group.serializers import GroupInfoSerializer, GroupUserInfoSerializer, GroupPhotoInfoSerializer | 
| 12 | 13 |  | 
| 14 | +from utils.thumbnail_utils import make_thumb | |
| 13 | 15 | from utils.ip_utils import ip_addr | 
| 14 | 16 |  | 
| 15 | 17 | from curtail_uuid import CurtailUUID | 
| @@ -424,6 +426,11 @@ def flyimg_upload_api(request): | ||
| 424 | 426 | default_storage.delete(photo_thumbnail_path) | 
| 425 | 427 | default_storage.save(photo_thumbnail_path, photo) | 
| 426 | 428 |  | 
| 429 | + make_thumb( | |
| 430 | +            os.path.join(settings.MEDIA_ROOT, photo_thumbnail_path).replace('\\', '/'), | |
| 431 | + settings.THUMBNAIL_MAX_WIDTH | |
| 432 | + ) | |
| 433 | + | |
| 427 | 434 | group_photo = GroupPhotoInfo.objects.create( | 
| 428 | 435 | group_id=group_id, | 
| 429 | 436 | user_id=user_id, | 
| @@ -154,6 +154,9 @@ CURTAIL_UUID_LENGTH = 7 | ||
| 154 | 154 | # 水印设置 | 
| 155 | 155 |  WATERMARK_LOGO = os.path.join(PROJ_DIR, 'static/pai2/img/paiai_96_96.png').replace('\\', '/') | 
| 156 | 156 |  | 
| 157 | +# 缩略图设置 | |
| 158 | +THUMBNAIL_MAX_WIDTH = 360 | |
| 159 | + | |
| 157 | 160 | # 域名设置 | 
| 158 | 161 | DOMAIN = 'http://xfoto.com.cn' | 
| 159 | 162 | IMG_DOMAIN = 'http://img.xfoto.com.cn' | 
| @@ -0,0 +1,17 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | + | |
| 3 | +from __future__ import division | |
| 4 | + | |
| 5 | +try: | |
| 6 | + from PIL import Image | |
| 7 | +except ImportError: | |
| 8 | + import Image | |
| 9 | + | |
| 10 | + | |
| 11 | +def make_thumb(im_path, max_width=360): | |
| 12 | + im = Image.open(im_path) | |
| 13 | + width, height = im.size | |
| 14 | + thumb_width = min(max_width, width) | |
| 15 | + thumb_height = height / width * thumb_width | |
| 16 | + im.thumbnail((thumb_width, thumb_height)) | |
| 17 | + im.save(im_path, im.format or 'JPEG') |