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

Support for saving lossless WebP #408

Closed
wants to merge 1 commit into from

Conversation

dhotson
Copy link

@dhotson dhotson commented Apr 12, 2016

Hello. :)

This PR adds initial support for saving lossless WebP.

Sharp usually saves WebP in lossy mode with a default quality of 80.
A bug that was fixed in libvips 8.3 means lossless WebP output is now possible.

To enable this in sharp, I've introduced an options object parameter to the webp method. e.g.

var image = sharp('file.png')
  .webp({ lossless: true });

I'd be happy to make changes to the API—please just let me know.

Also, I haven't added test cases since my test environment isn't working quite right. Once I've got that worked out—any thoughts on the kinds of tests you would like to see?

Todo

  • extra options parameter for toFormat() and other methods?
  • unit tests
  • documentation?

Example image output

PNG (lossless)

image


WebP (lossy - quality:80)

image


WebP (lossless)

image

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.1%) to 96.998% when pulling 52b18a2 on dhotson:webp-save-lossless into c4df560 on lovell:outfit.

@lovell
Copy link
Owner

lovell commented Apr 12, 2016

This is a great start, thanks Dennis, the proposed API looks good and your todo list is sensible.

You'll be pleased to know I'm currently working on libvips v8.3.0-pre binaries for the CI environments to use, including the addition of WebP support on Windows.

@lovell lovell added this to the v0.15.0 milestone Apr 12, 2016
@lovell lovell force-pushed the outfit branch 2 times, most recently from 082ca6e to 5b0f2d6 Compare May 1, 2016 08:02
@felixbuenemann
Copy link
Contributor

@dhotson There's more nice stuff coming for WebP in jcupitt/libvips#430.

One of the features added in that PR is near lossless encoding, which applies filtering to the image to improve compression. With moderate filtering you can likely reach ~50% of PNG24 filesize.

Another interesting one is the smart_subsample option, which greatly improves the perceived sharpness of fine details in lossy WebP images by using a smarter colorspace conversion that reduces color bleeding caused by chroma subsampling. With quality 85 and smart_subsample: true the lossless sample above would likely look much better at smaller filesize than lossless.

I tested several compression settings on the 600x600 RGBA sample image linked in the PR above:

  • 123K for PNG24
  • 83K WebP Lossless
  • 55k WebP Near Lossless
  • 13k WebP Lossy quality 85%, alpha quality 30%, smart subsampling on

The comparison only show PNG24 vs. WebP Lossy vs. WebP Lossy with smart subsample, which looks just as good as the PNG to me, while the normal lossy image looks poor even with quality 100%.

@dhotson
Copy link
Author

dhotson commented May 2, 2016

@felixbuenemann nice work! Should I close this PR? Does your PR include lossless webp as an option?

@dhotson dhotson closed this May 2, 2016
@felixbuenemann
Copy link
Contributor

@dhotson Please don't close this. I was talking about a libvips PR not sharp.

@dhotson dhotson reopened this May 2, 2016
@dhotson
Copy link
Author

dhotson commented May 2, 2016

Ah oops! I thought that linked PR was this repo. Reopening.. :)

@lovell
Copy link
Owner

lovell commented May 2, 2016

@dhotson When you next rebase your working branch against the outfit branch you'll pick up the commits for #369, which include changes that allow for the CI environments to work/pass again.

@lovell lovell force-pushed the outfit branch 2 times, most recently from c1df4ae to 7388d97 Compare May 8, 2016 12:31
@lovell lovell removed this from the v0.15.0 milestone May 8, 2016
@coveralls
Copy link

coveralls commented May 12, 2016

Coverage Status

Coverage decreased (-0.9%) to 97.959% when pulling 289aac9 on dhotson:webp-save-lossless into 051d022 on lovell:outfit.

@lovell
Copy link
Owner

lovell commented May 20, 2016

The outfit branch has now been merged into the master branch ahead of v0.15.0.

Let me know when you're ready to continue with this and we can work out the most suitable destination branch at the time.

@lovell lovell closed this May 22, 2016
@lovell
Copy link
Owner

lovell commented May 22, 2016

Oh, looks like Github auto-closed this PR when I removed the outfit branch.

@dhotson
Copy link
Author

dhotson commented May 22, 2016

Ah no problem—is this still something that you're interested in? I'm not sure where it stands alongside some of the other things that @felixbuenemann mentioned.

@lovell
Copy link
Owner

lovell commented May 22, 2016

Yes, I'm still interested in exposing WebP lossless available in libvips v8.3.1 as well as the new goodness such as smart_subsample that will be in the forthcoming libvips v8.4.0.

@Nantris
Copy link

Nantris commented Mar 31, 2018

Oddly, lossy webP on a 12kb image is resulting in a 21kb final image, whereas losseless is giving me a 5kb image at better quality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants