Skip to content

A modernized fork of pngcrush with libdeflate and Zopfli compression backends

License

Notifications You must be signed in to change notification settings

killerdevildog/PNGQrush

Repository files navigation

PNGqrush

A modernized fork of the classic pngcrush PNG optimizer with enhanced compression backends.

About

PNGqrush is a command-line utility that recompresses PNG image files to achieve optimal compression. It uses brute-force methods to try different filter methods and zlib compression levels to find the smallest possible file size without losing any image data (lossless compression).

This project is a modernization effort of the original pngcrush, which hasn't been actively updated in over 10 years. The goal is to bring this valuable tool up to date with modern compilers, systems, and best practices while maintaining full compatibility with the original functionality.

What's New in PNGqrush

Modern Compression Backends

PNGqrush extends the original pngcrush with state-of-the-art compression libraries:

Backend Compression Speed Use Case
zlib (default) Good Fast Standard compression
libdeflate Better (+5-10% smaller) Fast Default enhanced mode
Zopfli Best (+3-8% smaller than libdeflate) Very Slow (50-100x) When size matters most

Compression Comparison (Real World Example)

Method File Size Reduction
Original PNG 102,564 bytes
pngcrush (zlib-9) 92,185 bytes 10.1%
+ libdeflate-12 88,088 bytes 14.1%
+ Zopfli-15 83,507 bytes 18.6%

Other Improvements

  • Modern Build System: CMake 3.16+ with presets for debug, release, and sanitizer builds
  • Updated Libraries: zlib 1.3.1, libpng 1.6.54 (latest stable releases)
  • C11 Standard: Updated from C90 to C11 for modern compiler compatibility
  • Warning-Free: Compiles cleanly with -Wall -Wextra
  • Reorganized Structure: Clean separation of source code and third-party libraries

Features

  • Lossless PNG optimization through brute-force compression testing
  • Multiple compression backends: zlib, libdeflate, and Zopfli
  • Multiple filter method and compression level combinations
  • Chunk manipulation (add, remove, or modify PNG chunks)
  • Support for gAMA, sRGB, bKGD, tEXt/zTXt, and tRNS chunks
  • Automatic removal of invalid chunks with zero-filled data fields
  • Uses libpng and zlib for PNG processing

Project Structure

PNGqrush/
├── src/                    # Main source code
│   ├── pngcrush.c          # Main application
│   ├── pngcrush.h
│   ├── pngcrush_libdeflate.c/h  # libdeflate integration
│   ├── pngcrush_zopfli.c/h      # Zopfli integration
│   ├── cexcept.h           # Exception handling
│   └── config.h
├── thirdparty/             # Bundled third-party libraries
│   ├── libpng/             # libpng 1.6.54
│   ├── zlib/               # zlib 1.3.1
│   ├── libdeflate/         # libdeflate 1.22
│   └── zopfli/             # Zopfli 1.0.3
├── CMakeLists.txt          # Modern CMake build
├── CMakePresets.json       # CMake presets (debug, release, sanitizers)
├── Makefile                # Legacy GNU Make build
└── ROADMAP.md              # Modernization roadmap

Building

CMake (Recommended)

# Configure and build (release)
cmake --preset release
cmake --build build/release

# Debug build
cmake --preset debug
cmake --build build/debug

# With AddressSanitizer
cmake --preset asan
cmake --build build/asan

Legacy Makefile

make

Usage

pngqrush [options] input.png output.png

Compression Options

# Default: uses libdeflate-12 post-processing (recommended)
pngqrush input.png output.png

# Disable libdeflate, use zlib only
pngqrush -nolibdeflate input.png output.png

# Maximum compression with Zopfli (very slow, best results)
pngqrush -zopfli 15 input.png output.png

# Zopfli with more iterations (smaller but slower)
pngqrush -zopfli 100 input.png output.png

# Brute force all methods + libdeflate
pngqrush -brute input.png output.png

# Brute force + Zopfli for absolute smallest file
pngqrush -brute -zopfli 15 input.png output.png

CMake Build Options

Option Default Description
USE_LIBDEFLATE ON Enable libdeflate for enhanced compression
USE_ZOPFLI ON Enable Zopfli for maximum compression
USE_SYSTEM_ZLIB OFF Use system zlib instead of bundled
USE_SYSTEM_LIBPNG OFF Use system libpng instead of bundled

License

PNGqrush is released under a license derived from the libpng license. See LICENSE for full details.

Permission is hereby irrevocably granted to everyone to use, copy, modify, and distribute this source code, or portions hereof, or executable programs compiled from it, for any purpose, without payment of any fee, subject to the following restrictions:

  1. The origin of this source code must not be misrepresented.
  2. Altered versions must be plainly marked as such and must not be misrepresented as being the original source.
  3. This Copyright notice, disclaimers, and license may not be removed or altered from any source or altered source distribution.

Bundled Libraries

This distribution includes the following third-party libraries:

Library Version License Description
libpng 1.6.54 libpng-2.0 PNG reference library
zlib 1.3.1 zlib Compression library
libdeflate 1.22 MIT Fast DEFLATE compression
Zopfli 1.0.3 Apache-2.0 Maximum DEFLATE compression
cexcept 2.0.1 Public Domain Exception handling for C

Contributing

Contributions to modernize and improve PNGqrush are welcome! Please feel free to submit issues and pull requests.

Disclaimer

This computer program is supplied "AS IS". The authors disclaim all warranties, expressed or implied, including, without limitation, the warranties of merchantability and of fitness for any purpose.


Third-Party Acknowledgments & Licenses

pngcrush (Original)

This project is based on the original pngcrush created by:

  • Glenn Randers-Pehrson (Copyright © 1998-2002, 2006-2017)
  • Greg Roelofs (Portions Copyright © 2005)

The original pngcrush source code can be found at: http://pmt.sf.net/pngcrush/

libpng

PNG Reference Library License version 2

Copyright (c) 1995-2024 The PNG Reference Library Authors. Copyright (c) 2018-2024 Cosmin Truta. Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson. Copyright (c) 1996-1997 Andreas Dilger. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.

The software is supplied "as is", without warranty of any kind. Permission is hereby granted to use, copy, modify, and distribute this software for any purpose, without fee, subject to the restrictions in the LICENSE file.

zlib

Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler

This software is provided 'as-is', without any express or implied warranty. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the restrictions in the LICENSE file.

libdeflate

Copyright 2016 Eric Biggers Copyright 2024 Google LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the conditions in the COPYING file.

Zopfli

Copyright 2011 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Authors:

See the COPYING file for the full Apache 2.0 license text.

cexcept

Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta

This software is released to the public domain. No warranty is provided.


Maintainer

PNGQrush is maintained by Quaylyn Rimer (@killerdevildog)

Copyright © 2024-2026 Quaylyn Rimer. All rights reserved.

About

A modernized fork of pngcrush with libdeflate and Zopfli compression backends

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published