Skip to content
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

The quality paramater is ignored when producing a lossless webp #1740

Closed
redneb opened this issue Jun 4, 2019 · 6 comments
Closed

The quality paramater is ignored when producing a lossless webp #1740

redneb opened this issue Jun 4, 2019 · 6 comments

Comments

@redneb
Copy link

redneb commented Jun 4, 2019

I have the following piece of code

await sharp("input.png")
.webp({lossless: true, quality: 30})
.toBuffer();

The issue is that changing the quality value seems to have no effect. I was expecting that it would allow me to control the compression level/speed. This exactly what the cli tool cwebp does with the -q flag when used in lossless mode.

@lovell
Copy link
Owner

lovell commented Jun 4, 2019

Hello, the forthcoming method flag will do this - please see #1545

@lovell lovell added the question label Jun 4, 2019
@redneb
Copy link
Author

redneb commented Jun 4, 2019

Hi,

The introduction of the method parameter would certainly help, but it appears that it is complementary to quality. Here's what the man page of cwebp says about those two parameters:

-q float
Specify the compression factor for RGB channels between 0 and 100. The default is 75.
In case of lossy compression (default), a small factor produces a smaller file with lower quality. Best quality is achieved by using a value of 100.
In case of lossless compression (specified by the -lossless option), a small factor enables faster compression speed, but produces a larger file. Maximum compression is achieved by using a value of 100.

and

-m int
Specify the compression method to use. This parameter controls the trade off between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. Default value is 4. When higher values are used, the encoder will spend more time inspecting additional encoding possibilities and decide on the quality gain. Lower value can result in faster processing time at the expense of larger file size and lower compression quality.

There is also a related parameter, -z, which specifies a lossless preset. It's essentially a way to simply set both quality and method:

-z int
Switch on lossless compression mode with the specified level between 0 and 9, with level 0 being the fastest, 9 being the slowest. Fast mode produces larger file size than slower ones. A good default is -z 6. This option is actually a shortcut for some predefined settings for quality and method. If options -q or -m are subsequently used, they will invalidate the effect of this option.

I am not sure how this parameter is exposed by libwebp, but here's the relevant part in the code.

@redneb redneb changed the title The quality paramater is ignored when production a lossless webp The quality paramater is ignored when producing a lossless webp Jun 4, 2019
@lovell
Copy link
Owner

lovell commented Jun 5, 2019

I've opened libvips/libvips#1331 to add support for this to libvips.

@xiekevin
Copy link

Hi, any update on this issue?

@lovell lovell added this to the v0.23.0 milestone Jul 25, 2019
@lovell
Copy link
Owner

lovell commented Jul 25, 2019

This is dependent on libvips v8.8.1.

@lovell
Copy link
Owner

lovell commented Jul 29, 2019

sharp v0.23.0 / libvips v8.8.1 now available.

@lovell lovell closed this as completed Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants