-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Expose mozjpeg quant_table flag #1285
Conversation
Hei Espen, thanks for this PR, I should be able to take a closer look in a couple of days. I think it might reveal a small bug in the way libvips currently only sets the table based on |
I've compiled against libvips 8.6.4 and mozjpeg 3.3.1, and I think you're onto something, but I'm not seeing quite the behavior you are suggesting. It seems to me that (with this PR, at least) I am able to freely change between the different quantization tables: onst sharp = require('./')
async function main() {
for (let i = 8; i >= 0; i--) {
await sharp('img.jpg')
.resize(1024, 1024)
.max()
.jpeg({
optimizeCoding: false,
quantisationTable: i
})
.toBuffer()
.then(res => console.log('Table %d, %d bytes', i, res.length))
.catch(err => console.error(err))
}
}
main() Yields the following output:
As you pointed out however, libjpegs default quantization table is 0, while mozjpeg is 3, and this PR sets it to 0 by default. Not sure how you'd prefer it to be set by default? |
Thanks for checking. I'd forgotten about the libvips logic, which I added, to reset mozjpeg to use libjpeg defaults and therefore table 0 - see jcupitt/libvips@00e27de#diff-6e6f82dc292e7f7f8d223ff3dff4c7faR913 |
Thank you, this will be in v0.20.6. |
Thanks a bunch, Lovell! sharp is fantastic ❤️ |
This exposes the quant_table flag from mozjpeg, which previously had the libjpeg/mozjpeg default of
0
. Will use0
as the default, but now it's possible to choose a specific quantisation table when paired with theoptimize_coding
flag that was recently added.This can be very useful in a certain cases where some tables provide a better quality/compression ratio for certain images, which opens up a few cool tricks.
I unfortunately could not figure out a way to run the tests in a reliable way since mozjpeg is usually not installed, but it seems other tests using mozjpeg features use a similar "same or less" approach - let me know if you have any pointers on how this can be improved. Perhaps if there was some way to check if mozjpeg is available, it could be exposed by sharp somehow and we could do a
skip
on the specific tests if not available?