Browse Source

增加角标

yhz 5 years ago
parent
commit
ffcc0c44cd
2 changed files with 29 additions and 1 deletions
  1. BIN
      internal/marker/marker.png
  2. 29 1
      package_web_record.py

BIN
internal/marker/marker.png


+ 29 - 1
package_web_record.py

@@ -4,6 +4,7 @@ import os.path
 import sys
 import json
 import importlib
+from PIL import Image, ImageDraw
 
 def packageWeb():
     if len(sys.argv) < 2:
@@ -201,7 +202,14 @@ def copyRes(game, sdk, subChannel, config):
         mipmapSupport = ['mipmap-xhdpi', 'mipmap-xxhdpi', 'mipmap-xxxhdpi']
         for mipmap in mipmapSupport:
             iconPath = os.path.join(subChannelPath, 'icon', mipmap, 'record_sdk_icon.png')
-            file_utils.copyFile(config['icon'], iconPath)
+            if mipmap == 'mipmap-xhdpi':
+                size = 96
+            elif mipmap == 'mipmap-xxhdpi':
+                size = 144
+            else:
+                size = 192
+            roundRectangleIcon(config['icon'], iconPath, size)
+            #file_utils.copyFile(config['icon'], iconPath)
 
     if 'splash' in config and os.path.exists(config['splash']):
         splashPath = os.path.join(subChannelPath, 'splash', 'drawable-hdpi', 'shanshen_sdk_launcher_bg.jpg')
@@ -236,6 +244,26 @@ def copyRes(game, sdk, subChannel, config):
             languagePath = os.path.join(subChannelPath, 'merge', item['apkLanguage'])
             file_utils.copyFile(item['language'], languagePath)
 
+def roundRectangleIcon(iconPath, outPath, outSize):
+    markerPath = os.path.join(file_utils.getFullInternalPath(), 'marker', 'marker.png')
+    img = Image.open(iconPath).resize((192, 192)).convert("RGBA")
+    marker = Image.open(markerPath).resize((192, 192)).convert("RGBA")
+    img.paste(marker, (0, 0), marker)
+
+    rad = 30  # 设置半径 
+    circle = Image.new('L', (rad * 2, rad * 2), 0)
+    draw = ImageDraw.Draw(circle)
+    draw.ellipse((0, 0, rad * 2, rad * 2), fill=255)
+    alpha = Image.new('L', img.size, 255)
+    w, h = img.size
+    alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
+    alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
+    alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
+    alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
+    img.putalpha(alpha)
+
+    img.resize((outSize, outSize)).save(outPath, 'png')
+
 def getPackagePath(basePath, packageName):
     '''
     包名对应的目录