-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Img: add method to check if image format is supported #6324
Comments
This seems very reasonable to me. Are implementations interested in this? I suspect that unlike |
In https://bugs.chromium.org/p/chromium/issues/detail?id=1197269#c3 it was pointed out that this is mostly handled by the proposal at https://github.com/dalecurtis/image-decoder-api/blob/master/explainer.md . |
The |
PNG had partial implementations too, and newer formats are more complicated, so it seems pretty certain that we'll get more partial implementations. (Also, JPEG defines support for arithmetic compression, but no browser supports it) |
I’m unsure where the draft spec for |
There's an open PR for merging image decoding into the WebCodecs spec, so I assume that's the most recent revision. |
Let me opine on codecs=. The features of a codec in the codec string are implied by the codecs "profile". For example, a user agent may support the "baseline" H.264 profile but not the "high" profile. Not all codecs have a profile (e.g. most audio codecs), in which cases the implication is that all features of the codec are supported. The codecs strings are complicated and are typically defined by those involved in specifying the codec features (e.g. https://www.webmproject.org/vp9/mp4/#codecs-parameter-string). The nice thing about strings is it avoids needing to add separate feature descriptions for the multitude of codec features (intractable). But, if such strings do not already exist for images (I'm not familiar enough to know), you'll want to take a great deal of care in minting them, probably involving the appropriate standards body for the given image. Not easy. |
If browsers will allow video formats in |
Given the discussion in w3c/webcodecs#750 this method will likely have to return a promise that is resolved from a task as well. And perhaps as Simon suggests it should allow for some ambiguity, though it might be weird for it to differ from Colleagues and I would be interested in adding such a method and willing to work on the specification changes needed for it. We were wondering if people had further opinions on the API shape we should take into account. |
|
Not sure this is true. The reasoning given there applies to WebCodecs but distinguishes it from |
I am not sure how the web page can benefit from knowing the decodable image formats. I think the page will be interested more in knowing whether a certain image is decodable by the browser or not. I think also listing all features for an image format and asking the browser to tell which feature is supported or not will be difficult. On Apple ports we rely on the system frameworks to do the decoding. So we have to keep the list of features in sync with the system frameworks and we have to make sure we reply correctly on down level OSs. I think the
|
@othermaciej w3c/webcodecs#750 (comment) asserts that |
Give web developers a means to determine which formats are supported by the img element. Fixes #6324.
While all web browsers support the JPEG and PNG image formats, checking for support for additional image formats is difficult from JavaScript (the
<picture>
element solves this in markup). Currently, detecting support for WebP and AVIF (or JPEG 2000 / JPEG XR) requires creating a single pixel image and seeing if it works [1]. This is less than ideal and will only get worse when / if support for newer image formats, such as JPEG XL and WebP2, is added by browsers.The solution to this is adding a method that allows for checking if an image format is supported by the browser, so a script that's loading an image can choose the appropriate image file to request (or can send the appropriate
Accept
header with XHR to let the server decide which file to send). Ideally, this would be similar to the existingHTMLMediaElement.canPlayType()
method for video / audio.[1] https://developers.google.com/speed/webp/faq#in_your_own_javascript
The text was updated successfully, but these errors were encountered: