mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-10 02:16:05 +00:00
Icon optimization woo (#8590)
This commit is contained in:
53
tools/DmiOpt/compress.py
Normal file
53
tools/DmiOpt/compress.py
Normal 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()
|
||||
BIN
tools/DmiOpt/lib/optipng.exe
Normal file
BIN
tools/DmiOpt/lib/optipng.exe
Normal file
Binary file not shown.
9
tools/DmiOpt/readme.md
Normal file
9
tools/DmiOpt/readme.md
Normal 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 .`
|
||||
Reference in New Issue
Block a user