[svgwg] Blob URL in SVG as references (#769)

upsuper has just created a new issue for https://github.com/w3c/svgwg:

== Blob URL in SVG as references ==
In the [Features](https://svgwg.org/svg2-draft/conform.html#features) section in SVG 2 spec, `references to external resources` is defined to be URLs which are neither referencing something inside the document, nor a data URI. (The same definition differs in the [SVG Integration](https://svgwg.org/specs/integration/#features) spec which there is #768 for.)

I'm wondering whether it makes sense to allow blob URLs when they are generated from a document in the same origin. This would be an good escape from external reference restriction, because it's not always efficient to encode external resources in data URI.

As an example, this code
```html
<!DOCTYPE html>
<img style="background: red">
<script>
  let img = document.querySelector('img');
  let canvas = document.createElement('canvas');
  canvas.width = 200;
  canvas.height = 200;
  let ctx = canvas.getContext('2d');
  ctx.fillStyle = 'green';
  ctx.fillRect(0, 0, 200, 200);
  canvas.toBlob(blob => {
    let url = URL.createObjectURL(blob);
    img.src = `data:image/svg+xml,
<svg xmlns="http://www.w3.org/2000/svg"
     width="200" height="200" viewBox="0 0 200 200">
  <image href="${url}" x="0" y="0" width="200" height="200" style="background: red" />
</svg>
`
  });
</script>
```
allows the generated SVG to reference some resources generated inside the current page.

As far as I can see, this example currently works in Firefox, but not Chrome or Safari.

It can be useful when you want to have a generated SVG to include
* external resources that the current document can obtain otherwise, or
* a generated image within the current document.

Generating such SVG can be helpful when you try to compose images then generate rasterized image (via painting the SVG to the canvas again).

Please view or discuss this issue at https://github.com/w3c/svgwg/issues/769 using your GitHub account

Received on Monday, 30 December 2019 23:12:25 UTC