Link

How to compress your PNG files with PNGCompressor

JDeli offers a tool to compress your PNG images called PNGCompressor. This tool can be used from the command line or within your own application. It also exposes static helper methods for Java developers to use.

JDeli can do this in ONE step with the compresspng method. You can also use this for multiple files. It also allows you to use the following options.

Options:

  • -Dorg.jpedal.overwrite=true (overwrite input files - by default is “false”)
  • -Dorg.jpedal.verbose=true (print status messages - by default is “false”)

Compress PNG file from Command Line or another language

java [options] -jar jdeli.jar --compresspng [pngfile [pngfile ...]]

Example 1:

java -jar jdeli.jar --compresspng file.png

Example 2 (multiple files):

java -jar jdeli.jar --compresspng file1.png file2.png

Example 3 (with overwrite option):

java -Dorg.jpedal.overwrite=true -jar jdeli.jar --compresspng /directory/*.png

Example 4 (with verbose option):

java -Dorg.jpedal.verbose=true -jar jdeli.jar --compresspng /directory/*.png

The output filename is the same as the input name except that _compressed will be appended to the name. E.g. file.png will become file_compressed.png This can be changed to overwrite the existing file by setting the overwrite setting to true.

Compressing PNG files in Java

PngCompressor.compress(new FileInputStream("/path/to/inputFile"),new FileOutputStream("/path/to/outputFile"));

The two variables for this method can be any type of the input/output stream. More information on the PNGCompressor can be found in our Javadoc.