Giter VIP home page Giter VIP logo

Comments (4)

Fuzzyma avatar Fuzzyma commented on July 18, 2024

Please create a codepen or jsfiddle with the reproduction.
You can also post the most relevant code here.
I am not downloading any files

from svg.js.

FlashTang avatar FlashTang commented on July 18, 2024

Please create a codepen or jsfiddle with the reproduction. You can also post the most relevant code here. I am not downloading any files

@Fuzzyma
I don't know how to upload svg file to jsfiddle, so here is the relevant code:

<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0, maximum-scale=3.0, minimum-scale=0.2,shrink-to-fit=YES">
        <title>img_svg_test</title>
    </head>


    <body>

        <div id="canvas"></div>

        <script src="./vendor/svg.min.js"></script>
        
        <script>
            
            var draw = SVG().addTo('#canvas')

            var image = draw.image();
            image.on(['load'],function(e){
                console.log("success");
                console.log(image.width());
                console.log(image.height());
            });

            image.on('error',function(e){
                console.log("error");
                console.log(image.width());
                console.log(image.height());
            });

            image.load("./1.svg");
            
        </script>

    </body>


</html>

and 1.svg

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink"
    preserveAspectRatio="none" x="0px" y="0px" width="200px" height="100px" viewBox="0 0 200 100">
    <defs>
        <g id="Layer0_0_FILL">
            <path fill="#0000FF" stroke="none" d="
M 200 100
L 200 0 0 0 0 100 200 100 Z" />
        </g>
    </defs>

    <g transform="matrix( 1, 0, 0, 1, 0,0) ">
        <use xlink:href="#Layer0_0_FILL" />
    </g>
</svg>

from svg.js.

FlashTang avatar FlashTang commented on July 18, 2024

Seems i used it wrong , this one is correct :

var image = draw.image('/path/to/image.jpg', function (event) {
  // image loaded
  // this is the loading event for the underlying img element
  // you can access the natural width and height of the image with
  // event.target.naturalWidth, event.target.naturalHeight
})

or

image.load('/path/to/another/image.jpg', callback)

Works fine now 👍

from svg.js.

Fuzzyma avatar Fuzzyma commented on July 18, 2024

glad it resolved itself!

from svg.js.

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.