sindresorhus / gulp-imagemin

Minify PNG, JPEG, GIF and SVG images
MIT License
1.9k stars 157 forks source link

How set MozJpeg to lossless mode? #344

Open Alexufo opened 4 years ago

Alexufo commented 4 years ago

Since 7.0.0 jpegtran replaced by mozjpeg. https://github.com/sindresorhus/gulp-imagemin/pull/336

But MozJpeg has only lossy mode. On main page of imagemin:

Comes bundled with the following lossless optimizers:
mozjpeg — Compress JPEG images
...

How I can use MozJpeg in lossless?

shrpne commented 4 years ago

You can install imagemin-jpegtran back and use it instead of mozjpeg.

But keep in mind that JPEG is lossy format by its nature, so there are rare cases when you really need to compress it losslessly. Mozjpeg will get you much better compression ratio

Alexufo commented 4 years ago

@shrpne I got a HIGHER file size after MOZjpeg. I compress files in Photoshop and put in folder where mozjpeg add useless data on default 75% quality now. It is a grave mistake to change default behavior of lossless compression to lossy just by one pull request. Documentation is wrong now.

shrpne commented 4 years ago

I'm sorry that mozjpeg can't reduce filesize after photoshop compression. To get the best results I don't compress images in Photoshop (export with 100%), and use mozjpeg with jpegtran together.

imagemin([
    mozjpeg(),
    jpegtran({progressive: true}),
])

It will lead to best quality and compression. If you compare photoshop compression with mozjpeg compression, you will notice, that photoshop produce more artifacts with less compression ratio

Also, documentation will be fixed soon #346 :)

Alexufo commented 4 years ago

MozJpeg has more effective encoder but it less effective if you will set quality by your eyes with PS. In total PS+lossless encode more effective. If you have a lot of images mozjpeg 68% will be good. It much faster for your time. I am waiting when somebody develop algorithm for adaptive encoding when you should not check rate quality/compression by her eyes. In this case mozjpeg with adaptive encoder became as best practice.