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

ImageEncoder is missing from WebCodecs #11

Open
slightlyoff opened this issue Jan 1, 2025 · 0 comments
Open

ImageEncoder is missing from WebCodecs #11

slightlyoff opened this issue Jan 1, 2025 · 0 comments

Comments

@slightlyoff
Copy link
Member

WebCodecs, today, provides:

  • AudioEncoder
  • AudioDecoder
  • VideoEncoder
  • VideoDecoder
  • ImageDecoder

The spec doesn't currently contain an ImageEncoder, and when I've discussed this with folks in the past, they suggest (ab)using <canvas>'s toDataURL() method. This is unsatisfying.

Most obviously, the lack of symmetry is problematic. VideoEncoder and AudioEncoder provide a wealth of controls not reflected in <canvas> + createImageBitmap() hacks for image encoding but which are naturally part of the underlying codec's APIs. To get a sense for this gap, you can see many of the unexposed dimensions in the interface of squoosh when toggling between browser encoding for JEPG and MozJEPG (see the "advanced" section).

Less obviously, toDataURL() and friends deal in blobs and provide a synchronous API, while ImageDecoder (correctly) exposes a Promise-based API for per-frame decode. A symmetric, async, per-frame encode API with similar levels of control should be made available to improve overall application responsiveness.

On a related note, popular implementations of toDataURL() are missing AVIF support. This is a gap that an official ImageEncoder class should also close.

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

No branches or pull requests

1 participant