Zopfli is a data compression algorithm that encodes data into the widely deployed DEFLATE format (known from the zip file format and zlib). Zopfli is regarded as the most size-efficient Deflate encoder available. A reference implementation is released as a free software programming library. The name is the Swiss German diminutive of “Zopf”, a special type of Hefezopf.
Properties and use case
Zopfli can output either raw Deflate data stream or encapsulated into gzip or zlib formats. It can be configured to do more or less iterations than the default 15 to trade in processing time for compression efficiency.
Using the default setting, it achieves typically about 5 % better compression than zlib but takes around 80 times longer. Decompression speed is practically unaffected.
Therefore, it is much less suited for on-the-fly compression and pays off if data gets compressed once and served a sufficiently large number of times. This is typically true for static web content that is served with usually Deflate-based HTTP compression or has a Deflate-based file format like PNG or WOFF font files. (Most web clients support only Deflate or gzip, and not more advanced formats like Brotli or xz.) Another field are software updates or downloads with software package files that have a zip-based format like Android application packages (APK) or Java Archives (JAR), especially over mobile connections.
The higher data density is achieved by using more exhaustive compression techniques. The method is based on iterating entropy modeling and a shortest path search algorithm to find a low bit cost path through the graph of all possible Deflate representations.
There is a reference implementation from the authors in the form of a programming library written in C. It is available as free software under the terms of version 2.0 of the permissive Apache License.
A first implementation in PHP can be found in php_zopfli. Because of the gzip/zlib-compatible data compression this library can also be used for compressing data before delivering it to the client like you would do with gzencode().
Zopfli is based on an algorithm from Jyrki Alakuijala. Zopfli was developed and implemented into a programming library by Google Inc. employees Jyrki Alakuijala and Lode Vandevenne as a sideproject in their “20 percent time”. It was first released to the public in March 2013. An official version 1.0.0 was released on April 25, 2013. The advent of Zopfli displaced Ken Silverman's KZIP as the most size-efficient DEFLATE implementation and 7-Zip's deflater as the most size-efficient freely licensed one. After several adaptations of Zopfli for PNG appeared on GitHub, the latest Git version of Zopfli has contained the PNG optimizer ZopfliPNG since May 2013.
The Zopfli algorithm can be used to compress Portable Network Graphics (PNG) files because PNG uses a DEFLATE compression layer. There is a PNG optimization tool named ZopfliPNG from the authors of Zopfli. The Zopfli algorithm has also been integrated into other PNG compression optimization tools like advpng from the AdvanceCOMP utility suite.
Silverman's KZIP-based PNG encoder PNGOUT used to be the single most size-efficient PNG encoder available. It was displaced by Zopfli-based PNG encoders and optimization tools.
- Project page on GitHub
- Google's Zopfli Compression Algorithm: Extract higher performance from your compressed files – TechRepublic.com
- "Compress data more densely with Zopfli - Google Developers Blog". Googledevelopers.blogspot.com. 2013-02-28. Retrieved 2013-05-01.
- "zopfli – Zopfli Compression Algorithm – Google Project Hosting". Code.google.com. Retrieved 2013-05-01.
- Description of the Debian package of Zopfli, https://packages.debian.org/jessie/zopfli
- Alexander Neumann (heise Developer), March 1, 2013: Zopfli: Neue Kompressionsbibliothek von Google (german)
- Sharwood, Simon (2013). "Google open sources very slow compression algorithm". The Register.
- ThinkDigit: Zopfli: Google's new data compression algorithm