Skip to content

Remove pngquant #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.0.0 (31.01.2022)

Removed [pngquant-bin](https://github.com/imagemin/pngquant-bin) due to license issues.


## 2.7.5 (23.09.2021)

Fixed “Cannot find module” error that occurred if Optimizt was installed using Yarn.
Expand Down
10 changes: 10 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Migration

## 2.7.5 → 3.0.0

[sharp](README.md#png) module is now used to process PNG files.

The size of PNG files and their visual quality may differ from files processed with older versions of Optimizt.

Also, when you process PNG files in lossless mode, Optimizt will now try to preserve the original visual quality of
the image.


## 1.0.1 → 2.0.0

There were no any breaking changes.
Expand Down
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,53 @@ find . -iname \*.jpg -exec optimizt {} +

### JPEG

In lossy mode [jpegoptim](https://github.com/tjko/jpegoptim) is used with flags: `--strip-all`,
`--all-progressive`, `--max=80`.
#### Lossy

Lossless mode uses [Guetzli](https://github.com/google/guetzli) encoder with `--quality 90` flag.
[jpegoptim](https://github.com/tjko/jpegoptim) with flags: `--strip-all`, `--all-progressive`, `--max=80`.

#### Lossless

[Guetzli](https://github.com/google/guetzli) with `--quality 90` flag.

Guetzli aims for excellent compression density at high visual quality.

If you re-optimize the same file in lossless mode, the file size may decrease, but the visual quality will also degrade.
Keep in mind that if you reoptimize the same file in lossless mode, the file size may decrease, but the visual quality
will also degrade.

### PNG

For both modes [pngquant](https://github.com/kornelski/pngquant) (lossy compressor) is used with flags:
`--speed 1`, `--strip`.
[sharp](https://github.com/lovell/sharp) with [parameters](https://sharp.pixelplumbing.com/api-output#png):

- **lossy**: `compressionLevel: 9`, `adaptiveFiltering: false`, `palette: true`
- **lossless**: `compressionLevel: 9`, `adaptiveFiltering: true`, `palette: false`

### GIF

For both modes [gifsicle](https://github.com/kohler/gifsicle) utility is used.
[gifsicle](https://github.com/kohler/gifsicle) with flags:

- **lossy**: `-O3`, `--lossy=100`
- **lossless**: no flags

### WebP

[sharp](https://github.com/lovell/sharp) with [parameters](https://sharp.pixelplumbing.com/api-output#webp):

- **lossy**: `quality: 85`, `lossless: false`
- **lossless**: `quality: 85`, `lossless: true`

Following flags is used in lossy mode: `-O3`, `--lossy=100`.
### WebP (GIF)

In lossless mode no additional flags is used.
[gif2webp](https://developers.google.com/speed/webp/docs/gif2webp) with flags:

### WebP & AVIF
- **lossy**: `-lossy`, `-min_size`
- **lossless**: no flags

For both modes [sharp](https://github.com/lovell/sharp) module is used.
### AVIF

In lossless mode an “lossless” option is used:
[sharp](https://github.com/lovell/sharp) with [parameters](https://sharp.pixelplumbing.com/api-output#avif):

- https://sharp.pixelplumbing.com/api-output#webp
- https://sharp.pixelplumbing.com/api-output#avif
- **lossy**: `lossless: false`
- **lossless**: `lossless: true`

## Integrations

Expand Down
42 changes: 29 additions & 13 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ find . -iname \*.jpg -exec optimizt {} +

### JPEG

По умолчанию, в режиме lossy, используется [jpegoptim](https://github.com/tjko/jpegoptim) с ключами: `--strip-all`,
`--all-progressive`, `--max=80`.
#### Lossy

В режиме lossless используется энкодер [Guetzli](https://github.com/google/guetzli) с ключом `--quality 90`.
[jpegoptim](https://github.com/tjko/jpegoptim) с ключами: `--strip-all`, `--all-progressive`, `--max=80`.

#### Lossless

[Guetzli](https://github.com/google/guetzli) с ключом `--quality 90`.

Guetzli позволяет получить высокий уровень компрессии и при этом сохранить хорошее визуальное качество изображения.

Expand All @@ -75,25 +78,38 @@ Guetzli позволяет получить высокий уровень ком

### PNG

В обоих режимах используется lossy-компрессор [pngquant](https://github.com/kornelski/pngquant) с ключами: `--speed 1`,
`--strip`.
[sharp](https://github.com/lovell/sharp) с [параметрами](https://sharp.pixelplumbing.com/api-output#png):

- **lossy**: `compressionLevel: 9`, `adaptiveFiltering: false`, `palette: true`
- **lossless**: `compressionLevel: 9`, `adaptiveFiltering: true`, `palette: false`

### GIF

В обоих режимах используется утилита [gifsicle](https://github.com/kohler/gifsicle).
[gifsicle](https://github.com/kohler/gifsicle) с ключами:

- **lossy**: `-O3`, `--lossy=100`
- **lossless**: без ключей

### WebP

[sharp](https://github.com/lovell/sharp) с [параметрами](https://sharp.pixelplumbing.com/api-output#webp):

- **lossy**: `quality: 85`, `lossless: false`
- **lossless**: `quality: 85`, `lossless: true`

При запуске в режиме lossy используются ключи: `-O3`, `--lossy=100`.
### WebP (GIF)

В режиме lossless дополнительные ключи не устанавливаются.
[gif2webp](https://developers.google.com/speed/webp/docs/gif2webp) с ключами:

### WebP & AVIF
- **lossy**: `-lossy`, `-min_size`
- **lossless**: без ключей

В обоих режимах используется модуль [sharp](https://github.com/lovell/sharp).
### AVIF

Для режима lossless используется одноимённая опция, которая гарантирует сжатие без потерь:
[sharp](https://github.com/lovell/sharp) с [параметрами](https://sharp.pixelplumbing.com/api-output#avif):

- https://sharp.pixelplumbing.com/api-output#webp
- https://sharp.pixelplumbing.com/api-output#avif
- **lossy**: `lossless: false`
- **lossless**: `lossless: true`

## Интеграции

Expand Down
4 changes: 2 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ program

program
.usage('[options] <dir> <file ...>')
.version(require('./package').version, '-V, --version')
.description(require('./package').description)
.version(require('./package.json').version, '-V, --version')
.description(require('./package.json').description)
.parse(process.argv);

if (!program.args.length) {
Expand Down
13 changes: 6 additions & 7 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const gif2webp = require('gif2webp-bin');
const pLimit = require('p-limit');
const sharp = require('sharp');

const calcRatio = require('../lib/calcRatio');
const getImageFormat = require('../lib/getImageFormat');
const formatBytes = require('../lib/formatBytes');
const getPlural = require('../lib/getPlural');
const { log } = require('../lib/log');
const showTotal = require('../lib/showTotal');
const calcRatio = require('./calcRatio');
const getImageFormat = require('./getImageFormat');
const formatBytes = require('./formatBytes');
const getPlural = require('./getPlural');
const { log } = require('./log');
const showTotal = require('./showTotal');

async function convert({ paths, lossless, avif, webp, force }) {
const totalPaths = paths.length;
Expand Down Expand Up @@ -168,7 +168,6 @@ async function createAvif({ fileBuffer, lossless }) {

return sharp(fileBuffer)
.avif({
quality: 50,
lossless,
})
.toBuffer();
Expand Down
3 changes: 2 additions & 1 deletion lib/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function log(title = '', { type = 'info', description, verboseOnly } = {}) {
if (!isVerbose && verboseOnly && type === 'info') return;

console.log(
colorize(symbols[type][symbolIndex])[colors[type]], title,
colorize(symbols[type][symbolIndex])[colors[type]],
title,
...description ? [EOL, ' ', colorize(description).dim] : [],
);
}
Expand Down
27 changes: 14 additions & 13 deletions lib/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ const gifsicle = require('gifsicle');
const guetzli = require('guetzli');
const jpegoptim = require('jpegoptim-bin');
const pLimit = require('p-limit');
const pngquant = require('pngquant-bin');
const sharp = require('sharp');
const svgo = require('svgo');

const calcRatio = require('../lib/calcRatio');
const formatBytes = require('../lib/formatBytes');
const getImageFormat = require('../lib/getImageFormat');
const getPlural = require('../lib/getPlural');
const setSrgbColorspace = require('../lib/setSrgbColorspace');
const { log } = require('../lib/log');
const showTotal = require('../lib/showTotal');
const calcRatio = require('./calcRatio');
const formatBytes = require('./formatBytes');
const getImageFormat = require('./getImageFormat');
const getPlural = require('./getPlural');
const setSrgbColorspace = require('./setSrgbColorspace');
const { log } = require('./log');
const showTotal = require('./showTotal');

const svgoConfig = require('../svgo/config');

Expand Down Expand Up @@ -197,11 +196,13 @@ async function optimizeByType({ fileBuffer, filePath, isLossless }) {
return fileBuffer;
}

return execBuffer({
bin: pngquant,
args: ['--speed', '1', '--strip', '--output', execBuffer.output, execBuffer.input],
input: fileBuffer,
});
return sharp(fileBuffer)
.png({
compressionLevel: 9,
adaptiveFiltering: isLossless,
palette: !isLossless,
})
.toBuffer();

case '.gif':
if (imageFormat !== 'gif') {
Expand Down
Loading