html icon indicating copy to clipboard operation
html copied to clipboard

canvas.toDataUrl / toBlob should let you specify lossless compression for webp

Open Fuzzyma opened this issue 4 years ago • 3 comments

There is no way to specify lossless compression for the webp codec. Chrome seems to treat a quality of 1 as lossless (which is not really correct). There were discussions about adding a third parameter specifying a lossless flag or adding a special mimetype for losslesswebp. However, the only logical thing in my opinion is to allow to pass an object as second parameter with the encoderOptions (funny enough MDN already calls the second parameter "encoderOptions" which would suggest an object).

This solution would allow for more specific encoder options as well. webp alone has tons of it. Options that are not supported by the browser could simply be ignored.

Fuzzyma avatar Sep 16 '21 19:09 Fuzzyma

cc @whatwg/canvas

annevk avatar Sep 20 '21 10:09 annevk

Yeah, a dictionary here is probably a good idea.

kdashg avatar Sep 20 '21 19:09 kdashg

Bump. libwebp which is included in every browser's source code supports lossless encoding out of the box and the files created are much smaller than PNGs. Only the flag needs to be passed. When calling canvas.toDataUrl / toBlob allowing passing an object with options that can be interpreted individually by every codec instead of a single float seems like a natural step forward

DVLP avatar May 26 '25 06:05 DVLP