Bug 188347 - Calling .decode() on Image instance referencing an SVG throws an EncodingError
Summary: Calling .decode() on Image instance referencing an SVG throws an EncodingError
Status: RESOLVED DUPLICATE of bug 201243
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari 11
Hardware: Macintosh Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
Depends on:
Reported: 2018-08-06 07:47 PDT by Marcel Miranda
Modified: 2019-09-01 13:14 PDT (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Marcel Miranda 2018-08-06 07:47:25 PDT
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))

Comment 1 Said Abou-Hallawa 2018-08-06 09:38:28 PDT
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.
Comment 2 Simon Fraser (smfr) 2018-08-06 11:14:51 PDT
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.
Comment 3 Said Abou-Hallawa 2019-09-01 13:14:40 PDT

*** This bug has been marked as a duplicate of bug 201243 ***