Skip to content

Specify what the viewport should be when drawing SVG to a canvas #1880

@jakearchibald

Description

@jakearchibald

I've filed an issue with SVG, as displaying SVG in an image doesn't seem well-defined w3c/svgwg#289

However, we need to define how SVG is drawn to a canvas, particularly in terms of media queries.

canvas2dContext.drawImage(img, x, y, width, height);

Edge uses the layout size of the <img> to determine the viewport. If the <img> doesn't have layout then it falls back to the width/height attributes, if it doesn't have those it falls to the intrinsic dimensions of the <img>. This seems ideal, as you can change the viewport independent of the size it's drawn to the canvas.

At the moment every browser does something different here. Documentation and demos: https://jakearchibald.com/2016/svg-media-queries/#drawing-svg-to-a-canvas

Metadata

Metadata

Assignees

No one assigned

    Labels

    interopImplementations are not interoperable with each othertopic: canvas

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions