Icon optimization woo (#8590)

This commit is contained in:
sood
2016-05-01 12:15:17 -07:00
committed by clusterfack
parent 23b2a6bd2b
commit 155b9fc760
3 changed files with 62 additions and 0 deletions

53
tools/DmiOpt/compress.py Normal file
View File

@@ -0,0 +1,53 @@
from glob import glob
import os
from PIL import Image, PngImagePlugin
import logging
import subprocess
from itertools import chain
# Proper logging.
info = logging.getLogger(__name__).info
# Set the max to something large, so we are sure that it's all getting read.
PngImagePlugin.MAX_TEXT_CHUNK = 1000000000
def main():
# Setup logging configuration.
logging.basicConfig(
level=logging.NOTSET,
format=("%(relativeCreated)04d %(process)05d %(threadName)-10s "
"%(levelname)-5s %(msg)s")
)
# Walk down trough the local directory for dmi files.
dmiFiles = (chain.from_iterable(glob(os.path.join(x[0], '*.dmi')) for x in os.walk('.')))
for x in dmiFiles:
info("Calculating zTXt for {0}".format(x))
# Open the .dmi file so we can read the headers.
try:
imageFile = Image.open(x, "r")
# Create meta object to store info in.
meta = PngImagePlugin.PngInfo()
# Store metadata
for k, v in imageFile.info.iteritems():
meta.add_text(str(k), str(v), 0)
# Close the image
imageFile.close()
# Create new process
subprocess.call(["tools/DmiOpt/lib/optipng.exe", "--force", "-o 1", x])
# Merge headers with produced DMI
Image.open("{0}-fs8.png".format(x), "r").save(x, "PNG", pnginfo=meta, optimize=True)
# Remove .png file
os.remove("{0}-fs8.png".format(x))
except:
info("Unable to read {0}".format(x))
if __name__ == "__main__":
main()

Binary file not shown.

9
tools/DmiOpt/readme.md Normal file
View File

@@ -0,0 +1,9 @@
### DMICompress ###
This library requires https://github.com/python-pillow/Pillow to be installed via pip.
## Usage for /vg/ ##
Run:
cd into vgstation base directory
`python tools\DmiOpt\compress.py .`