Giter Club home page Giter Club logo

Comments (4)

Kaiido avatar Kaiido commented on May 25, 2024

One of the advantages of having to go through an <img> element is that this allows for easier sandboxing of the SVG image. For instance here I modified the original fiddle to show both the in DOM <svg> and the one drawn on the canvas. We wouldn't want the :visited selector to be leaked in the canvas where it can be read back.

So this means that the browser can't go directly from the image rendered into the doc to the canvas, it will have to recompute it there, or to taint the canvas which puts quite a limit on the feature.

I'd personally propose that if we do this for <svg>, why not do it for any element? IIRC there was already a proposal for such an "any element as source" idea, though I can't find it right now.

from html.

hfmanson avatar hfmanson commented on May 25, 2024

Indeed, CanvasRenderingContext2D.drawImage() does not render the image, but its bitmap which is a bit confusing (better name drawBitmap?). So passing a SVGSVGElement is not appropriate for drawImage().
bitmap only is demonstrating the above. When drawing the image on the canvas opacity is not applied, just the image bitmap is drawn.

I could change the proposal to "add CanvasRenderingContext2D.drawDocument() method", which has the same signature a drawImage apart for its first parameter which would be a document instead of an image-like parameter with a bitmap. The semantics can be the same as when a SVG image src is supplied, which also converts a SVG to a bitmap.

I think having a drawImage with any element as parameter is not possible, e.g. it's not possible to draw a SVG circle without it's svg document. Is that correct?

from html.

annevk avatar annevk commented on May 25, 2024

@Kaiido makes a good point that it needs the same restrictions as <img> SVG, so perhaps this isn't worth doing. Supporting arbitrary (styled) node trees without revealing anything about the end user is rather involved and not something anyone has been willing to take on thus far.

from html.

hfmanson avatar hfmanson commented on May 25, 2024

having read @Kaiido's comment I think the semantics of drawImage() having a SVGSVGElement as parameter should be as if it would be rendered through an <img> element.

from html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.