修复奇怪问题

This commit is contained in:
2022-12-18 18:00:19 +08:00
parent 1d7bd94908
commit 33be2db48f
18 changed files with 185 additions and 32 deletions

View File

@@ -1,10 +1,50 @@
import PIL.Image as Image
import PIL.ImageDraw as ImageDraw
import xml.etree.ElementTree as ET
import zipfile
import subprocess
import re
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''import xml.etree.ElementTree as ET
def xml2svg(xml_file):
tree = ET.parse(xml_file)
root = tree.getroot()
svg_str = '<svg>'
for child in root:
svg_str += '<' + child.tag
for attr in child.attrib:
svg_str += ' ' + attr + '="' + child.attrib[attr] + '"'
svg_str += '>'
for sub_child in child:
svg_str += '<' + sub_child.tag
for attr in sub_child.attrib:
svg_str += ' ' + attr + '="' + sub_child.attrib[attr] + '"'
svg_str += '/>'
svg_str += '</' + child.tag + '>'
svg_str += '</svg>'
return svg_str'''
class getsavexml():
'''def xml2svg(xml_file):
tree = ET.parse(xml_file)
root = tree.getroot()
svg_str = '<svg>'
for child in root:
svg_str += '<' + child.tag
for attr in child.attrib:
svg_str += ' ' + attr + '="' + child.attrib[attr] + '"'
svg_str += '>'
for sub_child in child:
svg_str += '<' + sub_child.tag
for attr in sub_child.attrib:
svg_str += ' ' + attr + '="' + sub_child.attrib[attr] + '"'
svg_str += '/>'
svg_str += '</' + child.tag + '>'
svg_str += '</svg>'
return svg_str'''
def savexml(self,apkFilePath,xmlpath,iconSavePath):
cmddumpid = "aapt dump xmltree "+ apkFilePath + " " + xmlpath
@@ -70,18 +110,37 @@ class getsavexml():
return imgpath
# 获取到文件列表后,进行比较分辨率,选取分辨率最高的张图片
iconbackpath = getmaxsize(backimgs)
iconforepath = getmaxsize(foreimgs)
print(iconbackpath + " " + iconforepath)
# /home/gfdgd_xi/Downloads/MT2.12.2.apk
try:
iconbackpath = getmaxsize(backimgs)
iconforepath = getmaxsize(foreimgs)
except:
if len(backimgs):
iconbackpath = backimgs[0]
else:
iconbackpath = ""
if len(foreimgs):
iconforepath = foreimgs[0]
else:
iconforepath = ""
print(iconbackpath, iconforepath)
#从APK文件获取最终图片
zipapk = zipfile.ZipFile(apkFilePath)
iconback = zipapk.open(iconbackpath)
iconfore = zipapk.open(iconforepath)
try:
iconback = zipapk.open(iconbackpath)
except:
iconback = None
try:
iconfore = zipapk.open(iconforepath)
except:
iconfore = None
# 叠加图片mask 设置前景为蒙版
iconbackimg = Image.open(iconback).convert("RGBA")
try:
iconbackimg = Image.open(iconback).convert("RGBA")
except:
pass
iconforeimg = Image.open(iconfore).convert("RGBA")
iconbackimg.paste(iconforeimg,mask=iconforeimg)