Sign inSign up

uroesch/pngpetite

By uroesch

•Updated over 3 years ago

A script to reduce the size of PNG images significantly.

Image
0

1.8K

uroesch/pngpetite repository overview

⁠pngpetite

A script to reduce the size of PNG images significantly. The code is based on Crush⁠ by Christopher Simpkins and has been adapted to Linux by refactoring it. As the code base shows significant differences the name has also been changed.

⁠Prerequisites

⁠Usage

Usage:
  pngpetite <options> <png-image> ...

Options:
  -h | --help         This message
  -r | --replace      Replace file with processed one
                      Implies -d
  -d | --dest <path>  Place images in given path
                      Implies -r
  -S | --no-stats     Don't print stats
  -q | --quiet        Don't print stats and progress
  -V | --version      Print version and exit

Description:
  Insane(ly slow but wicked good) PNG image optimization
  Built with pngquant and zopflipng optimizers

⁠Examples

Default usage. Yields happy-sun-pngpetite.png.

pngpetit happy-sun.png
Original (KB)   Stage1 (KB)    Final (KB)    Saved (KB)       Saved %    Time (sec)  Image Name
------------- ------------- ------------- ------------- ------------- -------------  -------------
       25.639        16.186        13.857        11.781        45.951        22.204  happy-sun.png

Replace existing image. Yields happy-sun.png.

pngpetit --replace happy-sun.png
Original (KB)   Stage1 (KB)    Final (KB)    Saved (KB)       Saved %    Time (sec)  Image Name
------------- ------------- ------------- ------------- ------------- -------------  -------------
       25.639        16.186        13.857        11.781        45.951        22.204  happy-sun.png

Place processed image in new directory. Yields pngpetite/happy-sun.png.

pngpetit --dest pngpetite happy-sun.png
Original (KB)   Stage1 (KB)    Final (KB)    Saved (KB)       Saved %    Time (sec)  Image Name
------------- ------------- ------------- ------------- ------------- -------------  -------------
       25.639        16.186        13.857        11.781        45.951        22.204  happy-sun.png

Process all PNG images in directory originals and place them in directory pngpetite..

pngpetite --dest pngpetite original/*png
Original (KB)   Stage1 (KB)    Final (KB)    Saved (KB)       Saved %    Time (sec)  Image Name
------------- ------------- ------------- ------------- ------------- -------------  -------------
      695.867       695.867       658.104        37.764         5.427        20.190  original/beach.png
       25.639        16.186        13.857        11.781        45.951        22.197  original/happy-sun.png
       54.101        29.885        27.244        26.856        49.642         8.097  original/shinkansen-n700.png

⁠Docker usage

docker run \
  --rm \
  --tty \
  --volume "$(pwd)":"$(pwd)" \
  --workdir "$(pwd)" \
  --user "$(id -u):$(id -g)" \
  uroesch/pngpetite <PNG image> [<PNG image> ...]

Or simply use the docker-pngpetite wrapper script found in the bin directory.

bin/docker-pngpetite <PNG image> [<PNG image> ...]

⁠Visual Examples

pngpetite is not suited for every type of picture. Especially photographic images may not yield high savings. To visualize the differences between the original image and the optimzed one, google’s butteraugli⁠ tools is used.

The values presented below were done on an Ubuntu 20.10 machine with:
pngquant 2.12.0 (January 2018)
zopfli 1.0.3
Your milage may vary.

⁠Photographs
⁠Beach Sunset
Original (KB)Stage1 (KB)Final (KB)Saved (KB)Saved %Butteraugli Score
443.642164.648150.155293.48666.1542.676426

Processing Results

Noticeable is that at stage 1 pngquant shrinks the image by 62% in older versions photograpic pictures did only yield a reduction in size. At stage 2 zopflipng is able to squeeze another 4% from its compression algorithm. Comparing the two images with butteraugli shows a large differences especially in the sunset section of the image.

⁠Original

Beach sunset original

⁠Optimized

Beach sunset optimized by pngpetite 66.154% smaller

⁠Heatmap

Beach sunset heatmap - no differences

⁠Grey Cat
Original (KB)Stage1 (KB)Final (KB)Saved (KB)Saved %Butteraugli Score
567.165204.628192.016375.14966.1453.551921

Processing Results

The heatmap shows clearly where the biggest differences occur during the processing. Notable are they eyes and the background. The fur is very similar to the orignial image.

⁠Original

Grey cat original

⁠Optimized

Grey cat optimized by pngpetite 66.145% smaller

⁠Heatmap

Grey cat heatmap - differences expecially in the eye region

⁠Illustrations
⁠Happy Sun
Original (KB)Stage1 (KB)Final (KB)Saved (KB)Saved %Butteraugli Score
30.32117.32615.68314.63948.2790.309227

Processing Results

The images are nearly similar the butteraugli heatmap does not have any red in it just a few areas in the face of the sun.

⁠Original

Happy sun original

⁠Optimized

Happy sun optimized by pngpetite 48.279% smaller

⁠Heatmap

Happy sun heatmap - differences arround the face

⁠Shinkansen N700
Original (KB)Stage1 (KB)Final (KB)Saved (KB)Saved %Butteraugli Score
52.33624.22622.68629.65056.6541.674651

Processing Results

Large savings with a few diffrences in the under carriages as the heatmap shows.

⁠Original

Shinkansen N700 original

⁠Optimized

Shinkansen N700 optimized by pngpetite 56.654% smaller

⁠Heatmap

Shinkansen N700 heatmap - differences in the undercarriage

⁠Known issues

  • Under Docker the time statistics are not yet working correctly

⁠Attribution

⁠Images

Tag summary

Content type

Image

Digest

sha256:67ee0b9ae…

Size

7.1 MB

Last updated

over 3 years ago

docker pull uroesch/pngpetite