Learn how to install the Crunch tool in Ubuntu 19.04 to decrease insanely PNG files keeping almost the same quality.

How to install Crunch in Ubuntu 18.04 and mega compress PNG images (lossy PNG image file optimization)

The crunch command line executable is a *nix executable that supports parallel PNG image optimization with local (off of the system PATH) installs of the pngquant and zopflipng project dependencies. Compilation of pngquant and zopflipng from source is supported (and mandatory) as part of the installation process.

In this tutorial, we will explain you how to easily install and use the Crunch utility to compress brutally PNG images in Ubuntu 18.04.

A. Installing Crunch

As first step, you will need to clone the repository of Crunch. This repository contains the source code of the project. You can easily obtain the source code of the project using git (sudo apt-get install git in case you don't have it):

# Change of directory, a regular one like Downloads
cd ~/Downloads

# Clone the repository
git clone https://github.com/chrissimpkins/Crunch.git

# Get into the crunch directory
cd Crunch

Now that you have the source code, you will be able to build it from scratch and its dependencies as well using Make. Start this with the following command (located in the cloned repository):

make build-dependencies

This will take a while as it will download the source of PNGQuant and zopflipng. Wait until it finishes and when it's done, proceed to expose the binary into the PATH with the following command:

make install-executable

This requires super user rights, so be sure to provide your root password when it's requested. You can confirm finally if it was succesfully installed running the following command in your terminal:

crunch --help

This will generate an output similar to:

///////////////////////////////////////////////////
 crunch
  Copyright 2018 Christopher Simpkins
  MIT License

  Source: https://github.com/chrissimpkins/Crunch
///////////////////////////////////////////////////

crunch is a command line executable that performs lossy optimization of one or more png image files with pngquant and zopflipng.

Usage:
    $ crunch [image path 1]...[image path n]

Options:
    --help, -h      application help
    --usage         application usage
    --version, -v   application version

For more information about this tool, please visit the official repository at Github here.

B. Using Crunch

Now, Crunch is a CLI tool that allows you to process images that are provided as positional arguments in the command. For example, to compress an image:

crunch ./image.png

The tool will compress the image in the current directory and it will take a while as mentioned in the description of the tool. Once it finishes, you will find in the same directory a new file with the crunch suffix e.g image-crunch.png. For example, for a picture in PNG format of 622.9 KB with a resolution of 3286x1080 pixels, it took 13.48 seconds to generate a compressed version of 192.6 KB in a computer with the following specifications:

  • Intel® Core™ i7-7700 CPU @ 3.60GHz × 8
  • 7,7 GiB Ram
  • GeForce GTX 1050/PCIe/SSE2
  • Gnome 3.32.1
  • 64-bit
  • HDD 2,1 TB

That's an insane optimization!

C. Updating Crunch

Crunch, unlike other tools isn't available through apt-get, so you will need to update it manually. For this, be sure to have the latest version of the source code available in some directory, then remove the dependencies from the home directory and repeat the installation steps:

# If you have already the source code of Crunch,
# just switch to the directory e.g cd Crunch
git clone https://github.com/chrissimpkins/Crunch.git
cd Crunch

# Remove dependencies
rm -rf ~/pngquant
rm -rf ~/zopfli

# Rebuild and add to path
make build-dependencies
make install-executable

This will ensure that you always have the latest version of crunch !

D. Uninstall Crunch

If you are willing now to remove Crunch from your system, you may simply switch to the cloned source code, and run the make commands for it:

# If you have already the source code of Crunch,
# just switch to the directory e.g cd Crunch
git clone https://github.com/chrissimpkins/Crunch.git
cd Crunch

# Uninstall dependencies
make uninstall-dependencies

# Remove executable
make uninstall-executable

Happy compression ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors