GithubHelp home page GithubHelp logo

chrissimpkins / crunch Goto Github PK

View Code? Open in Web Editor NEW
3.3K 65.0 147.0 33.8 MB

Insane(ly slow but wicked good) PNG image optimization

License: Other

Shell 8.62% HTML 11.44% Makefile 3.65% Python 76.30%
png png-compression compression image-quality image-processing images image image-compression pngquant zopflipng

crunch's Introduction

Crunch PNG file optimizationCrunch PNG file optimization Crunch PNG file optimization

GitHub release Linux Python CI macOS Python CI Lints Benchmarks

About

Crunch is a tool for lossy PNG image file optimization. It combines selective bit depth, color type, and color palette reduction with zopfli DEFLATE compression algorithm encoding using the pngquant and zopflipng PNG optimization tools. This approach leads to a significant file size gain relative to lossless approaches at the expense of a relatively modest decrease in image quality (see example images below).

Continuous benchmark testing is available in our GitHub Actions CI. Please see the benchmarks directory of this repository for details about the benchmarking approach and instructions on how to execute benchmarks locally on the reference images distributed in this repository or with your own image files.

Crunch PNG image optimization is available through the following applications that are distributed in this repository:

  • crunch - a *nix command line executable that can be used on macOS, Linux, and Windows POSIX application deployment environments such as Cygwin or the Windows subsystem for Linux
  • Crunch GUI - a native macOS drag and drop GUI tool
  • Crunch Image(s) service - a macOS right-click menu service for PNG images selected in the Finder

Installation and Usage

Installation and usage documentation links for each of the Crunch applications are available below.

crunch Command Line Executable

The crunch command line executable can be installed with make or manually. Please see the Install documentation.

Enter paths to your PNG image files as arguments to the crunch executable. Please see the Usage documentation.

Crunch macOS GUI Application

The Crunch native macOS GUI application can be installed with Homebrew or the dmg installer that can be downloaded from the repository releases. Please see the Install documentation.

Drag and drop one or more images on the application window to process your PNG files. Please see the Usage documentation.

Crunch Image(s) macOS Right-Click Menu Service

The macOS right-click menu service "Crunch Image(s)" can be installed with make or manually by drag and drop in the macOS Finder. Please see the Install documentation.

Select one or more PNG images in the Finder, right-click, and select the Services > Crunch Image(s) menu item to process your files. Please see the Usage documentation.

Contents

Examples

The following examples demonstrate the benefits and disadvantages of the current iteration of Crunch's aggressive space saving optimization strategy. The optimized image files are updated at every Crunch release. In many cases, the PNG optimization decreases file size with an imperceptible impact on image quality. In some cases, degradation of image quality is visible. Visual confirmation of image quality is highly recommended with lossy optimization tools in production settings.

Photography Examples

Cat Image

  • Original Size: 583,398 bytes
  • Optimized Size: 196,085 bytes
  • DSSIM similarity score: 0.001383
  • Percent original size: 33.61%
Original

cat example pre optimization

Optimized

cat example post optimization

Sun's Rays

  • Original Size: 138,272
  • Optimized Size: 66,593
  • DSSIM similarity score: 0.000920
  • Percent original size: 48.16%
Original

sun rays example pre optimization

Optimized

sun rays example pre optimization

Prairie Image

  • Original Size: 196,794 bytes
  • Optimized Size: 77,965 bytes
  • DSSIM similarity score: 0.002923
  • Percent original size: 39.62%
Original

prarie example pre optimization

Optimized

prarie example post optimization

Illustration Examples

Robot Image

  • Original Size: 197,193 bytes
  • Optimized Size: 67,596 bytes
  • DSSIM similarity score: 0.003047
  • Percent original size: 34.28%
Original

robot example pre optimization

Optimized

robot example post optimization

Color Circle Image

  • Original Size: 249,251 bytes
  • Optimized Size: 67,135 bytes
  • DSSIM similarity score: 0.002450
  • Percent original size: 26.93%
Original

colors example pre optimization

Optimized

colors example post optimization

Flowers Image

  • Original Size: 440,126 bytes
  • Optimized Size: 196,962 bytes
  • DSSIM similarity score: 0.001013
  • Percent original size: 44.75%
Original

748

Optimized

748

All images above were obtained from Pixabay and are dedicated to the public domain under the CC0 Public Domain Dedication.

DSSIM testing was performed with v2.10.0 of the kornelski/dssim tool.

Issue Reporting

Have you identified a problem? Please create a new issue report on the Github issue tracker so that we can address it.

Licenses

Crunch is licensed under the MIT license.

Embedded Software

pngquant is licensed under the Gnu General Public License, version 3. The pngquant source code is available here.

zopflipng is licensed under the Apache License, Version 2.0. The upstream zopflipng source code is available here. The source for the modified zopflipng fork that is used in this project is available here.

See the LICENSE.md document for details and additional licensing information for this project.

Contributing

Contributions to the project are warmly welcomed. Please suggest enhancements as new issue reports on this repository. Source contributors should fork the git repository and submit changes as a Github pull request.

Acknowledgments

Crunch is a simple tool that makes excellent, free, open source software built by others more accessible. The hard work on the optimization engines that run Crunch has been performed by:

The fantastic macOS GUI animations were designed by Gary Jacobs.

crunch's People

Contributors

abbudao avatar chrissimpkins avatar dsouzarc avatar garyjacobs avatar kawarimidoll avatar kcy1019 avatar kimond avatar perillamint avatar xjohn600 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crunch's Issues

pngquant libraries not loaded dmg installer & homebrew cask install approaches (libpng + little-cms2) [fixed!]

After installing wthe DMG file and dragging the PNG, this is what I got:

dyld: Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib Referenced from: /Applications/Crunch.app/Contents/Resources/./pngquant Reason: image not found /Applications/Crunch.app/Contents/Resources/script: line 10: 6549 Abort trap: 6 ./pngquant --quality=80-98 --skip-if-larger --force --ext -crunch.png "$imagepath" > /dev/null

@chrissimpkins edits below -------

Associated closed issue reports to limit discussion to this thread:

#10
#12

TODO:

  • update homebrew cask install script with pngquant dependencies (fix confirmed for those who install with homebrew cask in #7 (comment))
  • definitive solution is to use static linking for these libraries in the pngquant compile. New issue report #13 opened to address this. A new release will be prepared with this fix. I think that a transition to dynamic library linking may have happened at some stage along the way in the pngquant compile and I missed it... (this should be fixed in v1.0.1, awaiting confirmation)

FIX IS AVAILABLE (v1.0.1)

For those who previously used the Homebrew Cask installer

Try to install with the Homebrew cask install approach again. The installer script was updated with a couple of new dependencies and this should now be fixed

For those who want to install with the dmg installer

Please attempt your install with the v1.0.1 build. This should be the fix for this issue. Feedback needed to confirm and close this issue report.

https://github.com/chrissimpkins/Crunch/releases/tag/v1.0.1

Only support PNG compression?

Hello, it's a great privilege to see Crunch open source 👏🏼, but currently only support PNG compression?

English is not my native language; please excuse typing errors.

🤔

macOS GUI fails with space in absolute filepath [FIX AVAILABLE FOR TESTING]

I noticed this evening that Crunch will only execute successfully when I drag in PNG files from my Mac desktop into the GUI. If I drag them in from a folder on the desktop (eg. desktop/folder/image.png) then crunching fails to execute.


@chrissimpkins edits below:

Fix available for testing in #38 for anyone who is affected by this issue. Please weigh in on whether this fixes it for you in this thread. Thanks.

Autoupdate macOS GUI with Homebrew cask

Homebrew cask now supports the following command which will automatically update the Crunch macOS GUI installed through Homebrew cask to new releases since you last installed/updated:

$ brew cask upgrade

Thanks to @adidalal for this information in #49 (comment). Will update documentation on the README and in the macOS GUI About text.

TODO:

  • update macOS GUI About text with homebrew cask upgrade approach to upgrades
  • update macOS GUI repository documentation with homebrew cask upgrade approach to upgrades

Add parallel image processing support

Include:

  • Automated testing for multiple image requests
  • Automated process spawns up to number of available CPU

Will support much faster optimization for multi image requests on multi processor machines

Crunch 1.0 (installer) doesn't work but brew 0.9.0 does

Crunch 1.0 (installer) doesn't work but brew 0.9.0 does
Mac OS X 10.10.5

dyld: Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib Referenced from: /Volumes/Crunch Installer/Crunch.app/Contents/Resources/./pngquant Reason: Incompatible library version: pngquant requires version 51.0.0 or later, but libpng16.16.dylib provides version 47.0.0 /Volumes/Crunch Installer/Crunch.app/Contents/Resources/script: line 10: 64882 Trace/BPT trap: 5 ./pngquant --quality=80-98 --skip-if-larger --force --ext -crunch.png "$imagepath" > /dev/null

screen shot 2018-03-26 at 16 57 47

the older 0.9.0 installed by brew works just fine
screen shot 2018-03-26 at 16 57 53

Weird installer

Is it expected that make build-dependencies should produce hundreds of pages like this:

image

...and then create these 2 folders in the user folder:

image

Dependency build failures due to Sourceforge libpng download interruption

Test builds of the pngquant and zopflipng dependencies just began failing today with the following error during the attempt to build pngquant:

xz: (stdin): File format not recognized
tar: Child returned status 1
tar: Error is not recoverable: exiting now
src/install-dependencies.sh: 46: cd: can't cd to libpng-1.6.34
make: *** [build-dependencies] Error 1

This occurs when you build these dependencies with make build-dependencies in order to use the command line executable.

This is happening because the Sourceforge file server is down and the libpng source code download is not accessible. libpng is a requirement for pngquant builds. You can check on availability with the following download link: https://download.sourceforge.net/libpng/libpng-1.6.34.tar.xz

When the source pulled through that link is available, this error should disappear.

This error does not apply to the macOS GUI or macOS right click menu service.

DMG version - pngquant missing

Dyld Error Message:
Library not loaded: /usr/local/opt/libpng/lib/libpng16.16.dylib
Referenced from: /Applications/Crunch.app/Contents/Resources/./pngquant

Max CPU on idle (Mojave, GUI)

Describe the bug
Upon opening crunch GUI, CPU usage sits 94-98%, even when no image has been optimised.

To Reproduce
Steps to reproduce the behavior:

  1. Open 'application...'
  2. Open activity monitor

Expected behavior
No cpu usage while idle

Screenshots and/or Log Text
screenshot 2018-06-12 at 09 57 47

Adams-MBP:~ adamtester$ cat ~/.crunch/crunch.log
06-12-18 09:56:39	INFO	[ 42.47% ] /Users/adamtester/Downloads/menu-logo-crunch.png (1984 bytes)
06-12-18 09:56:39	INFO	Crunch execution ended.

Desktop (please complete the following information):

  • OS: macOs 10.14 Beta
  • Version: Crunch 3.0.0 GUI installed from prebuilt dmg

Additional context
Using beta macOS

Bump pngquant to v2.12.0

Improved speed on large image files

TODO:

  • update compile script
  • update embedded macOS GUI binary

Update zopflipng

Latest release is in the google/zopfli repository is tagged zopfli-1.0.1. Commits to master since include google/zopfli@e0e937e that suggest there may be improvements in compression of smaller files.

@lvandeve Lode, is the tip of google/zopfli master stable for production use? The latest tagged release was zopfli-1.0.1 (google/zopfli@89cf773) back in 2015. This is what I am using here to compile the zopflipng executable but more recent commit messages suggest there may have been compression improvements for smaller pre-files since that time. I don't see a test suite to confirm on my own.

TODO:

  • update compile shell script (ed06efa)
  • build new embedded executable for macOS GUI and right click menu service (ba8d0db)

Create a new custom zopflipng build

I am tweaking the upstream google/zopfli source to achieve better zopflipng compression with 8-bit quantized PNG files. This custom zopflipng build will be included in the v3.0.0 release of Crunch. This build of zopflipng will be available for use through all of the Crunch tools. Work is taking place in chrissimpkins/zopfli. Testing is being performed on the true color PNG files in the Kodak Image Suite.

This issue replaces #34

  • add embedded binary to macOS GUI (also supports the right-click menu service on macOS)
  • create a tagged release of zopfli
  • update dependency build script

Update README.md to show percentage of memory saved

For each of the demo pictures in README.md, it might be useful to show the percentage of memory saved by using Crunch's optimizations alongside the Original/Optimized Size and DSSIM similarity score.

Memory saved = (Original_Size - Optimized_Size) / Original_Size

option: Cover the original file

Hi Crunch team,

Life saving tool!!!
Could you add a function that allow user to cover the original files directly with the crunched files generated? Thank you!

Greetings from Holland.
Bikman

Updated GUI animations

Here are some updated animations for the GUI version of "Drag and Drop"

There are 5 states outlined as follows:

01-Load-Up.gif
This should play once and then switch to "Waiting"

02-Waiting.gif
This will loop and wait until the user places file(s) onto the GUI window

03-Crunching.gif
This will loop while the magic is happening

04-Error.gif
This will play once when something went Wrong (error)

04-Success.gif
This will play once when the compression is complete and state in view for 1-2 secs then reset back to "Waiting GIF".

Dimensions of animations are 600x300 - these would look best filling the entire container it sits in.

Open to suggestions on wording and visuals displayed here.

01-load-up
02-waiting
03-crunching
04-error
04-success


@chrissimpkins edits below:

TODO:

  • window size increase vs. image size decrease (vs. existing window design) - keep existing size
  • decide license for these images - MIT license, no change #39 (comment)
  • submit PR with images placed in img directory
  • update animations in Crunch macOS GUI tool
  • release the new success/failure status indicator animations with new logging of failures (#37)
  • update About window text with acknowledgment
  • update README documentation with acknowledgment
  • update macOS GUI Usage documentation animated gif image with new design

Issues with filenames containing spaces/special characters

I just testes Crunch with a file named MILITARY 2016-04-10 15.47.11.png (a screenshot from the console game Military Madness). Stage 1 worked somehow, Stage 2 did not at all:

• • • Crunching /Users/[REDACTED]/MILITARY 2016-04-10 15.47.11.png...

Original size (kB):     471.940

==> Running stage 1 optimizations...
stat: /Users/[REDACTED]/MILITARY 2016-04-10 15-crunch.png: stat: No such file or directory

(standard_in) 1: parse error
Current size (kB):  0.000

==> Running stage 2 optimizations...
==> Hold tight.  This could take awhile.
==> Click Cancel at any time to save at the above size.
[ERROR] Unable to access the file for optimizations.  Please report this issue.
stat: /Users/[REDACTED]/MILITARY 2016-04-10 15-crunch.png: stat: No such file or directory

---
Optimized filepath: /Users/[REDACTED]/MILITARY 2016-04-10 15-crunch.png
(standard_in) 1: parse error
Final size  (kB):   0.000
(standard_in) 1: parse error
Percent original:   0.00%
(standard_in) 1: parse error
Space saved (kB):   0.000

---

Where it works well, where it does not...

I would like to pull together more data on use cases where this is an appropriate tool and use cases where it is not. My experience is limited to the image types that I commonly make/use and I can say that after a couple of years' experience with the approach here it seems to be:

Useful, appropriate for:

  • small color ranges
  • limited range to no color gradients (subset of above issue)
  • black/white without wide grey range transitions (maybe? I haven't looked at much here)

Probably/maybe not appropriate for:

  • wide color ranges
  • color gradients (subset of above issue)

I would like to open this up for conversation with others out there so that we have a breadth of experience across different image styles. We can be objective about this by testing with the DSSIM tool across different types of image files. My gist is that as this value reaches and exceeds a value of 0.002 my eye begins to notice artifacts. It is possible that this could be turned into a parameter for the optimizations if it is real and able to be further generalized.

Goal will be to:

(1) document this for those who are interested in the tool
(2) further optimize the strategy used here by having much more objective data to base the optimization settings on. I think that we may be able to find a way to improve the compression ratios further, but likely only for certain types of image files.

If you have any thoughts, please weigh in and post examples of your images pre/post. If you have the ability to do so, please measure the DSSIM score for your pre/post optimization files with the open source dssim tool that is available here: https://github.com/kornelski/dssim (and include the version of the dssim tool that you used!)

Thanks!

Auto-update (or update notification) for GUI

First, great work on the app!

It would be great to see an auto-update feature added to the GUI. If that's more work than you care to take on, a simple notification that an update is available when the app is launched would be sufficient.

Thanks!


@chrissimpkins edits below:

Current approach for auto-updates of macOS GUI application is through Homebrew cask with the following command after a previous install:

$ brew cask upgrade

This checks for a new version c/w your currently installed version and automatically upgrades if a more current release is available. The Homebrew installation approach remains the recommended approach for the macOS GUI tool in this project.

See #49 (comment) for an approach to upgrades if you do not have Homebrew installed on your macOS system.

Be more up front that this is lossy compression

I think you should say up front, quite clearly, that this is lossy compression. I wasn't aware of that until you mentioned in another issue.

The word lossy is only mentioned once in the README in the "Examples" section.

Given that repeat processing of the same file can degrade image quality it's quite important for people to know they should keep their master images around.

Add option to overwrite original

Normally I want just to compress the original exported assets so would be nice to have an "overwrite original" option

Thanks for the great work 👍

crunch2 app exists with same application name

crunch2.com
now https://getcrunch.co

"If you like writing Less instead of CSS, you shouldn’t have to run scripts in your terminal like this is 1992, or install apps that do nothing except babysit your style files.

Crunch lets you write Less, Sass, CoffeeScript, Markdown*, and then automatically saves CSS, JavaScript, and HTML after you’ve made changes. Want to write just plain CSS? XML? Haskell? MUSHCode? Crunch lets you do that too.

Crunch 2 is an editor that lets you do what you want. Because Crunch loves you."

Not working .dmg

Hi! I already installed the .dmg for mac (High Sierra), moved it into applications folder and then open it. After that, I try to drag files into the application but nothing happens...

Fix for multiple directory levels with spaces in path names macOS GUI + right-click menu service

This issue only affects the macOS GUI and macOS right-click menu service tools. It does not affect the command line executable crunch.

#30 was not fully addressed as intended in the v2.0.2 release. As of v2.0.2, images on paths that include spaces within the path at more than one directory level will not be optimized. Fix in the works and will be available as part of the v2.1.0 release #46

Workaround: remove spaces in the absolute path to your image file(s).

cc:@masey9

PNG Format partially working

Hi Chris,

Attached are the PNG images in question.
They were all exported from Sketch from a single symbol. So in theory they are all the same image just at different sizes.

spacexflight3l
spacexflight3m
spacexflight3s
spacexflight3t

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.