在包体积中,较大的图片资源会严重影响包的体积,可以通过以下方式进行大图的筛选,进行压缩或者放置远端处理.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import glob, os
filesList = [] unsupports = []
rootPath = '/Users/jinying.zhou.o/Documents/NIO/NIO/NextevCar'
def get_FileSize(filePath): fsize = os.path.getsize(filePath) fsize = fsize/float(1024) return round(fsize,2)
filesList = []
bigSizeList = []
totalSize = 0.0
bigTotalSize = 0.0 for root, dirs, files in os.walk(rootPath): for file in files: if file.endswith(".png"): tempPath = root + '/' + os.path.join(file) tempSize = get_FileSize(tempPath) totalSize += tempSize tempStr = tempPath + ' ' + str(tempSize) + "KB" if tempSize > 100: bigSizePath = tempPath + ' ' + str(tempSize) + 'KB' bigTotalSize += tempSize bigSizeList.append(bigSizePath)
print("=================================以下为大图===============================") for bigPath in bigSizeList: print(bigPath) print("项目中图片总大小为"+ str(totalSize) + 'KB') print("超过100K的图片大小总size为" + str(bigTotalSize) + "KB")
|