Bug 188347
| Summary: | Calling .decode() on Image instance referencing an SVG throws an EncodingError | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Marcel Miranda <m> |
| Component: | DOM | Assignee: | Said Abou-Hallawa <sabouhallawa> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | Normal | CC: | cdumez, dino, sabouhallawa, simon.fraser |
| Priority: | P2 | ||
| Version: | Safari 11 | ||
| Hardware: | Mac | ||
| OS: | Unspecified | ||
Marcel Miranda
Calling the decode method on an Image instance referencing a SVG file throws an EncodingError exception
I've created a small reproducible environment here: https://codesandbox.io/s/xl6mq18704
Code to replicate
```
function loadImage(src, onLoad) {
var image = new window.Image();
image.onload = function(e) {
image.decode().then(() => onLoad(e));
};
image.src = src;
return image;
}
loadImage('https://xl6mq18704.codesandbox.io/img/refresh.svg', (e) => document.body.appendChild(e.target))
```
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Said Abou-Hallawa
According to the specs https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element, the description of the decode() method is the following:
image . decode()
This method causes the user agent to decode the image in parallel, returning a promise that fulfills when decoding is complete.
The promise will be rejected with an "EncodingError" DOMException if the image cannot be decoded.
Image encoding is the process of compressing the image pixels data into a specialized format for efficient transmission or storage. Image decoding is the opposite process -- the conversion of an encoded format back into the original pixels data format.
It is clear that The SVG image is not represented in pixels format and it is not saved in compressed format, unless it is a base-64 data URL. But the decoding of the base-64 data URL is different from the HTMLImageElement.deocde() and it is done implicitly as part of loading the SVG image sub-resource.
So I think there is no bug here.
Simon Fraser (smfr)
I think SVG should fall into the "If decoding does not need to be performed for this image (for example because it is a vector graphic), resolve promise with undefined." case, not the exception throwing case.
Said Abou-Hallawa
*** This bug has been marked as a duplicate of bug 201243 ***