This repository contains batch scripts and executable comandline tools that compress PNG files using lossy and lossless methods and set the color of transparent pixels to a defined value.
For my mods, I had to compress PNG textures and spritesheets, but at the same time, set the RGB values of completely transparent pixels to 0,0,0. Since all of the maintained PNG quantization tools I know set the RGB values of transparent pixels to unpredictable values, I had to create a workaround. This resulted in the batch scripts contained here.
The batch script uses three command-line tools to process PNG and achieve the desired result.
-
Lossy compression with pngquant
-
Setting the RGB values of transparent pixels with ImageMagick
-
Further lossless compression with oxipng
- pngquant (pre-compiled binary taken from pngquant-bin)
- ImageMagick
- oxipng
- pngquant
--quality=75-100(Better than the default range of 65-80)--speed 1(best quality)--ext=.png(override existing files)--skip-if-larger--strip(remove metadata)
- ImageMagick
-define preserve-timestamp=true(retain timestamp)-background #000000(sets the RGB color of fully transparent pixels)
- qxipng
-opt max(maximum optimisation level)-strip safe(remove all non-critical metadata)-preserve(retain timestamp)
- Windows 10 or 11
Download and unzip the latest released source code (zip).
Drag and drop PNG files or folders including PNG files onto the coresponding .bat files. Drag and drop folders will process through all subfolders.
Be aware that the script modifies the files themselves.
Right-click the .bat file and choose Edit.
Find the following line:
"%path%/ImageMagick/magick.exe" %1 -verbose -define preserve-timestamp=true -background #000000 -alpha background %1
Change the HEX color definition after the -background comand to your desired color. Then, save and close.
- 1.0
- Initial Release
This project is licensed under the MIT License - see the LICENSE file for details
Please note the licenses for the command-line tools in their respective folders.
- pngquant (GNU GENERAL PUBLIC LICENSE Version 3)
- ImageMagick (license)
- qxipng (MIT license)