Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logo加载不出来 #8

Closed
VoliBearCat opened this issue Aug 4, 2017 · 4 comments
Closed

logo加载不出来 #8

VoliBearCat opened this issue Aug 4, 2017 · 4 comments

Comments

@VoliBearCat
Copy link

VoliBearCat commented Aug 4, 2017

            var avatar = new Image()
            avatar.src = this.imageURL
            new AwesomeQRCode().create({
              text: '这是怎么肥事???',
              size: 380,
              margin: 20,
              dotScale: 1,
              backgroundImage: undefined,
              logoImage: avatar,
              logoScale: .2,
              logoMargin: 4,
              autoColor: true,
              logoCornerRadius: 0,
              callback: function (dataURI) {
                // console.log(dataURI);
              },
              bindElement: 'qrcode'
            });

3ry j osln 9vkd x jd
rw b3xxq ha4u3 43nad

@sumimakito
Copy link
Owner

sumimakito commented Aug 4, 2017

Image in JavaScript will load the image from the given src asynchronously, so you need to know when the image has finished loading by adding a callback to img.

var img = new Image();
img.onload = function() {
    // Use the img
};
img.src = "Some URL";

You can also take a look at: https://jsfiddle.net/sumimakito/45L3okhe/1/

UPDATE:
To load images from external resources (i.e. cross-domain images), you may need to enable CORS loading for the Image.

var img = new Image();
img.crossOrigin = "Anonymous";
img.onload = function() {
    // Use the img
};
img.src = "Some URL";

Also, you can follow the steps in this article: https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image

@VoliBearCat
Copy link
Author

Thank you, I get it.

@VoliBearCat
Copy link
Author

I've tried onload function, but it still doesn't work.
The point is to set "crossorigin = 'anonymous'", find it from your demo.

@sumimakito
Copy link
Owner

sumimakito commented Aug 5, 2017

That's right. Without setting the "crossOrigin" property, the Image will suffer security issues while loading images from external resources.
For more information, you can refer to this article: https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants