diff --git a/tools/DmiOpt/compress.py b/tools/DmiOpt/compress.py new file mode 100644 index 00000000000..ad4f4af22ae --- /dev/null +++ b/tools/DmiOpt/compress.py @@ -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() diff --git a/tools/DmiOpt/lib/optipng.exe b/tools/DmiOpt/lib/optipng.exe new file mode 100644 index 00000000000..81cff3c5fe3 Binary files /dev/null and b/tools/DmiOpt/lib/optipng.exe differ diff --git a/tools/DmiOpt/readme.md b/tools/DmiOpt/readme.md new file mode 100644 index 00000000000..46419ce3cde --- /dev/null +++ b/tools/DmiOpt/readme.md @@ -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 .`