Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/freshleafmedia/image-compression-finder

Automatic detection of maximum compression without visually changing the image
https://github.com/freshleafmedia/image-compression-finder

automation compression image-compression image-processing

Last synced: 2 months ago
JSON representation

Automatic detection of maximum compression without visually changing the image

Awesome Lists containing this project

README

        

# Image Compression Finder

Automatic detection of maximum compression without visually changing the image.

## Overview

This is a library which attempts to determine the maximum amount of compression which can be applied
to an image while not introducing any visible changes.

The output is an integer between 0 and 100.

## Installation

```
composer require freshleafmedia/image-compression-finder
```

### DSSIM

A working copy of [kornelski/dssim](https://github.com/kornelski/dssim) must be installed.

To install the latest, at time of writing, on Ubuntu the following one-liner can be used:

```
curl -sSL https://github.com/kornelski/dssim/releases/download/3.2.3/dssim_3.2.3_amd64.deb > /tmp/dssim.deb && apt install /tmp/dssim.deb
```

### Imagick/GD

Either of Imagick or GD extensions are required.

## Usage

```php
use FreshleafMedia\ImageCompressionFinder\ImageCompressionFinder;

$quality = ImageCompressionFinder::make()->run('/path/to/image');

$quality; // 66 (0-100)
```

## How it works

The algorithm uses a binary search to repeatedly compress and test an image until the ideal quality is found

1. Compress the image with a quality setting of 60
2. Analyse the new image using DSSIM
3. If the change is within tolerance the quality is halved, if not it is increased by 50% (aka a binary search)
4. Compress the image again with the new quality
5. GOTO 2

## Options

There are a couple of configuration options:

```php
$quality = ImageCompressionFinder::make()
->maxDifference(0.001) // The highest acceptable visual change. 0-∞ where 0 is no change at all
->startingQuality(60) // Where to start the search
->driver('imagick') // The driver to use to compress images. Eg imagick or gd
->run();
```

## Tests

Unit tests can be run via `composer test`

## License

See [LICENSE](LICENSE)