Update water mark

Brightcells vor 8 Jahren
Ursprung
Commit
680f424408

+ 3 - 1
group/lensman_views.py

@@ -172,15 +172,17 @@ def lensman_photo_upload_api(request):
172 172
         group_id = group.group_id
173 173
 
174 174
     if photo and upload_lock(group_id, user_id, photo):
175
-        # 写 PhotosInfo 表
176 175
         photo_info = file_save(photo, prefix='photo', ext='jpeg', watermark=True, thumbnail=True)
177 176
 
177
+        # 写 PhotosInfo 表
178 178
         photo, created = PhotosInfo.objects.get_or_create(
179 179
             lensman_id=lensman_id,
180 180
             session_id=session_id,
181 181
             photo_id=photo_id,
182 182
         )
183
+        # 无水印
183 184
         photo.m_photo_path = photo_info.photo_path
185
+        # 有水印
184 186
         photo.p_photo_path = photo_info.photo_watermark_path
185 187
         photo.save()
186 188
 

+ 2 - 2
pai2/settings.py

@@ -233,7 +233,7 @@ FILE_UPLOAD_PERMISSIONS = 0o644  # TemporaryUploadedFile 文件权限设置
233 233
 CURTAIL_UUID_LENGTH = 7  # Used in django-curtail-uuid==1.0.0
234 234
 
235 235
 # 水印设置
236
-WATERMARK_LOGO = os.path.join(PROJ_DIR, 'static/pai2/img/paiai_96_96.png').replace('\\', '/')
236
+WATERMARK_LOGO = os.path.join(PROJ_DIR, 'static/pai2/img/paiai_water_mark.png').replace('\\', '/')
237 237
 
238 238
 # 原图设置
239 239
 LENSMAN_PHOTO_ORIGIN_EXPIRED_MSEL = 604800000  # 摄影师原图过期毫秒数,7d = 7 * 24 * 3600 * 1000msel
@@ -261,7 +261,7 @@ PAI2_TOURGUIDE_DOWNLOAD_IOS_PAGE_PATH = os.path.join(BASE_DIR, 'page/templates/p
261 261
 
262 262
 # 下载设置
263 263
 PAI2_USER_DOWNLOAD_WX_URL = 'https://pai.ai'
264
-PAI2_USER_DOWNLOAD_IOS_URL = 'https://pai.ai'
264
+PAI2_USER_DOWNLOAD_IOS_URL = 'https://itunes.apple.com/cn/app/pai-aipaiai/id1163960351?mt=8'
265 265
 
266 266
 PAI2_LENSMAN_DOWNLOAD_WX_URL = 'https://pai.ai'
267 267
 PAI2_LENSMAN_DOWNLOAD_IOS_URL = 'https://pai.ai'

BIN
pai2/static/pai2/img/paiai_water_mark.png


+ 1 - 1
photo/views.py

@@ -178,7 +178,7 @@ def session_join_api(request):
178 178
 
179 179
         group_photo = None
180 180
         for photo in photos:
181
-            photo_info = file_save(photo_path=photo.p_photo_path, thumbnail=True)
181
+            photo_info = file_save(photo_path=photo.p_photo_path, prefix='photo', ext='jpeg', thumbnail=True)
182 182
 
183 183
             # 群组照片记录创建
184 184
             group_photo = GroupPhotoInfo.objects.create(

BIN
utils/original_CGzC_10a50000c8811190.jpg


BIN
utils/paiai_water_mark.png


+ 7 - 2
utils/storage_utils.py

@@ -35,7 +35,7 @@ def file_save(file_=None, file_path=None, prefix='img', ext='jpeg', watermark=Fa
35 35
     # Photo UUID Get or Create
36 36
     photo, created = PhotoUUIDInfo.objects.select_for_update().get_or_create(photo_md5=photo_md5)
37 37
 
38
-    # 照片路径
38
+    # 无水印
39 39
     if not photo.photo_path:
40 40
         photo_path = '{}/{}{}'.format(prefix, shortuuid.uuid(), ext)
41 41
         if default_storage.exists(photo_path):
@@ -45,7 +45,7 @@ def file_save(file_=None, file_path=None, prefix='img', ext='jpeg', watermark=Fa
45 45
         photo.photo_path = photo_path
46 46
         photo.save()
47 47
 
48
-    # 水印
48
+    # 有水印
49 49
     if watermark:
50 50
         if not photo.photo_watermark_path:
51 51
             photo_watermark_path = 'photo/{}{}'.format(shortuuid.uuid(), ext)
@@ -80,6 +80,11 @@ def file_save(file_=None, file_path=None, prefix='img', ext='jpeg', watermark=Fa
80 80
                 os.path.join(settings.MEDIA_ROOT, photo_thumbnail2_path).replace('\\', '/'),
81 81
                 settings.THUMBNAIL_MAX_WIDTH2
82 82
             )
83
+            watermark_wrap(
84
+                os.path.join(settings.MEDIA_ROOT, photo_thumbnail2_path).replace('\\', '/'),
85
+                settings.WATERMARK_LOGO,
86
+                os.path.join(settings.MEDIA_ROOT, photo_thumbnail2_path).replace('\\', '/')
87
+            )
83 88
             photo.photo_w = photo_w
84 89
             photo.photo_h = photo_h
85 90
             photo.photo_thumbnail2_path = photo_thumbnail2_path

+ 20 - 17
utils/watermark_utils.py

@@ -17,46 +17,49 @@ def reduce_opacity(im, opacity):
17 17
     return im
18 18
 
19 19
 
20
-def watermark(im, mark, position, opacity=1):
21
-    """Adds a watermark to an image."""
20
+def watermark(im, mark, position, opacity=1, maxsize=(0, 0), possize=(0, 0)):
21
+    """ Add watermark to image """
22 22
     if opacity < 1:
23 23
         mark = reduce_opacity(mark, opacity)
24 24
     if im.mode != 'RGBA':
25 25
         im = im.convert('RGBA')
26
-    # create a transparent layer the size of the image and draw the
27
-    # watermark in that layer.
26
+    # Resize mark
27
+    w, h = int(min(mark.size[0], maxsize[0]) if maxsize[0] else mark.size[0]), int(min(mark.size[1], maxsize[1]) if maxsize[1] else mark.size[1])
28
+    mark = mark.resize((w, h))
29
+    # Create a transparent layer the size of the image
30
+    # Draw the watermark in that layer.
28 31
     layer = Image.new('RGBA', im.size, (0, 0, 0, 0))
29 32
     if position == 'tile':
30 33
         for y in range(0, im.size[1], mark.size[1]):
31 34
             for x in range(0, im.size[0], mark.size[0]):
32 35
                 layer.paste(mark, (x, y))
33 36
     elif position == 'scale':
34
-        # scale, but preserve the aspect ratio
35
-        ratio = min(
36
-            float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1])
37
-        w = int(mark.size[0] * ratio)
38
-        h = int(mark.size[1] * ratio)
37
+        # Scale, but preserve the aspect ratio
38
+        ratio = min(float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1])
39
+        w, h = int(mark.size[0] * ratio), int(mark.size[1] * ratio)
40
+        w, h = int(min(w, maxsize[0]) if maxsize[0] else w), int(min(h, maxsize[1]) if maxsize[1] else h)
39 41
         mark = mark.resize((w, h))
40
-        layer.paste(mark, ((im.size[0] - w) / 2, (im.size[1] - h) / 2))
42
+        layer.paste(mark, ((im.size[0] - possize[0] or w) / 2, (im.size[1] - possize[1] or h) / 2))
41 43
     else:
42 44
         layer.paste(mark, position)
43
-    # composite the watermark with the layer
45
+    # Composite the watermark with the layer
44 46
     return Image.composite(layer, im, layer)
45 47
 
46 48
 
47 49
 def watermark_wrap(im_path, mark_path, save_path=''):
48 50
     im, mark = Image.open(im_path), Image.open(mark_path)
49
-    new_im = watermark(im, mark, (50, 50), 0.5)
51
+    # new_im = watermark(im, mark, (50, 50), 0.5)
52
+    new_im = watermark(im, mark, position='scale', opacity=1.0, maxsize=(400, 494.375), possize=(400, 400))
50 53
     new_im.save(save_path or im_path)
51 54
 
52 55
 
53 56
 def watermark_test():
54
-    im, mark = Image.open('original_CGzC_10a50000c8811190.jpg'), Image.open('paiai_96_96.png')
55
-    watermark(im, mark, 'tile', 0.5).show()
56
-    watermark(im, mark, 'scale', 1.0).show()
57
-    watermark(im, mark, (50, 50), 0.5).show()
57
+    im, mark = Image.open('original_CGzC_10a50000c8811190.jpg'), Image.open('paiai_water_mark.png')
58
+    watermark(im, mark, position='tile', opacity=0.5, maxsize=(40, 49.4375)).show()
59
+    watermark(im, mark, position='scale', opacity=1.0, maxsize=(400, 494.375), possize=(400, 400)).show()
60
+    watermark(im, mark, position=(50, 50), opacity=0.5, maxsize=(40, 49.4375)).show()
58 61
 
59 62
 
60 63
 if __name__ == '__main__':
61 64
     # watermark_test()
62
-    watermark_wrap('original_CGzC_10a50000c8811190.jpg', 'paiai_96_96.png')
65
+    watermark_wrap('original_CGzC_10a50000c8811190.jpg', 'paiai_water_mark.png')