Pngtastic

repository·master·Indexed 42 days ago

https://github.com/depsypher/pngtastic

A lightweight, zero-dependency Java library for PNG image manipulation, focusing on file size optimization and layering. Designed to run in environments where AWT is unavailable, such as Google App Engine. Version 1.7 includes a CLI for optimization and supports Zopfli compression.

Tokens
1.1K
Snippets
4
Records
5
Agent score
3%

What's inside Pngtastic

  1. Overview of Pngtastic operations

    master

    Pngtastic is a pure Java API designed for PNG manipulation without AWT dependencies. Its core supported operations are:

    • File size optimization: Reducing the footprint of PNG files.
    • PNG image layering: Managing layers within PNG images.
  2. Install Pngtastic via Maven

    master

    Add the following dependency to your pom.xml to use Pngtastic in your Java project. Pngtastic is a zero-dependency library that does not rely on AWT, making it suitable for restrictive environments like Google App Engine.

    <dependency>
        <groupId>com.github.depsypher</groupId>
        <artifactId>pngtastic</artifactId>
        <version>1.7</version>
    </dependency>
  3. Optimize PNG images using the CLI

    master

    You can optimize PNG files via the command line using the com.googlecode.pngtastic.PngtasticOptimizer class.

    To achieve maximum compression ratios, use the --compressor zopfli flag. Note that Zopfli compression is slower but provides significantly better compression than the default compressor.

    CLI Arguments:

    • --compressor: Specifies the compression algorithm (e.g., zopfli).
    • --iterations: Number of Zopfli iterations (e.g., 32).
    • --fileSuffix: A suffix to append to the optimized filename (e.g., .min.png).
    • The final argument is the path to the input PNG file.
    $ java -cp target/pngtastic-1.8-SNAPSHOT.jar com.googlecode.pngtastic.PngtasticOptimizer --compressor zopfli --iterations 32 --fileSuffix .min.png images/optimizer/amigaball.png
  4. Zopfli CLI command line options

    master

    The following flags are available for the Zopfli CLI:

    FlagDescription
    -hDisplays the help message and exits.
    -cWrites the result to standard output instead of a file on disk.
    --i#Performs # iterations (e.g., --i50). Higher numbers increase compression ratio but decrease speed. Default is 15.
    --gzipSets output format to GZIP (default). Files will be saved as filename.gz.
    --zlibSets output format to ZLIB. Files will be saved as filename.zlib.
    --deflateSets output format to DEFLATE. Files will be saved as filename.deflate.
    --splitlastConfigures block splitting to occur last instead of first.
    Usage: zopfli [OPTION]... FILE
      -h    gives this help
      -c    write the result on standard output, instead of disk
            filename + '.gz'
      --i#  perform # iterations (default 15). More gives
            more compression but is slower. Examples: --i10, --i50, --i1000
      --gzip        output to gzip format (default)
      --zlib        output to zlib format instead of gzip
      --deflate     output to deflate format instead of gzip
      --splitlast   do block splitting last instead of first
  5. Use the Zopfli CLI for compression

    master

    The Zopfli CLI allows you to compress files using various deflate-based formats (GZIP, ZLIB, or DEFLATE) with configurable iteration counts and block splitting strategies.

    By default, the tool outputs to a file with a specific extension based on the format chosen (e.g., .gz for GZIP). You can redirect output to standard output using the -c flag.

    Usage Pattern: zopfli [OPTION]... FILE

    # Example: Compress a file with 50 iterations using GZIP format
    zopfli --i50 myfile.txt
    
    # Example: Output ZLIB compressed data to stdout
    zopfli --zlib -c myfile.txt