gulp-imagemin icon indicating copy to clipboard operation
gulp-imagemin copied to clipboard

How set MozJpeg to lossless mode?

Open Alexufo opened this issue 4 years ago • 4 comments

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?

Alexufo avatar Jun 16 '20 00:06 Alexufo

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

shrpne avatar Jul 16 '20 18:07 shrpne

@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.

Alexufo avatar Jul 16 '20 18:07 Alexufo

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 :)

shrpne avatar Jul 16 '20 19:07 shrpne

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.

Alexufo avatar Jul 17 '20 00:07 Alexufo