3 Run this script every time you change one of the png files. Using pngcrush, it will optimize the png files, remove various color profiles, remove ancillary chunks (alla) and text chunks (text). 4 #pngcrush -brute -ow -rem gAMA -rem cHRM -rem iCCP -rem sRGB -rem alla -rem text 13 '''Return hash of raw file contents''' 14 with open(filename,
'rb')
as f:
15 return hashlib.sha256(f.read()).hexdigest()
18 '''Return hash of RGBA contents of image''' 19 i = Image.open(filename)
22 return hashlib.sha256(data).hexdigest()
26 folders = [
"src/qt/res/movies",
"src/qt/res/icons",
"src/qt/res/icons/crownium",
"src/qt/res/icons/drkblue",
"src/qt/res/icons/light",
"src/qt/res/icons/trad",
"src/qt/res/images",
"src/qt/res/images/crownium",
"src/qt/res/images/drkblue",
"src/qt/res/images/light",
"src/qt/res/images/trad",
"share/pixmaps"]
27 basePath = subprocess.check_output([git,
'rev-parse',
'--show-toplevel']).rstrip(
'\n')
32 for folder
in folders:
33 absFolder=os.path.join(basePath, folder)
34 for file
in os.listdir(absFolder):
35 extension = os.path.splitext(file)[1]
36 if extension.lower() ==
'.png':
37 print(
"optimizing "+file+
"..."),
38 file_path = os.path.join(absFolder, file)
39 fileMetaMap = {
'file' : file,
'osize': os.path.getsize(file_path),
'sha256Old' :
file_hash(file_path)};
44 pngCrushOutput = subprocess.check_output(
45 [pngcrush,
"-brute",
"-ow",
"-rem",
"gAMA",
"-rem",
"cHRM",
"-rem",
"iCCP",
"-rem",
"sRGB",
"-rem",
"alla",
"-rem",
"text", file_path],
46 stderr=subprocess.STDOUT).rstrip(
'\n')
48 print "pngcrush is not installed, aborting..." 52 if "Not a PNG file" in subprocess.check_output([pngcrush,
"-n",
"-v", file_path], stderr=subprocess.STDOUT):
53 print "PNG file "+file+
" is corrupted after crushing, check out pngcursh version" 56 fileMetaMap[
'sha256New'] =
file_hash(file_path)
59 if fileMetaMap[
'contentHashPre'] != fileMetaMap[
'contentHashPost']:
60 print "Image contents of PNG file "+file+
" before and after crushing don't match" 63 fileMetaMap[
'psize'] = os.path.getsize(file_path)
64 outputArray.append(fileMetaMap)
67 print "summary:\n+++++++++++++++++" 68 for fileDict
in outputArray:
69 oldHash = fileDict[
'sha256Old']
70 newHash = fileDict[
'sha256New']
71 totalSaveBytes += fileDict[
'osize'] - fileDict[
'psize']
72 noHashChange = noHashChange
and (oldHash == newHash)
73 print fileDict[
'file']+
"\n size diff from: "+str(fileDict[
'osize'])+
" to: "+str(fileDict[
'psize'])+
"\n old sha256: "+oldHash+
"\n new sha256: "+newHash+
"\n" 75 print "completed. Checksum stable: "+str(noHashChange)+
". Total reduction: "+str(totalSaveBytes)+
" bytes" def content_hash(filename)