mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
fix: cross origin issue for image
This commit is contained in:
parent
6f0a575239
commit
5f6523164d
3 changed files with 20 additions and 1 deletions
|
|
@ -27,6 +27,10 @@
|
|||
<body>
|
||||
|
||||
<div id="mount"></div>
|
||||
<div>
|
||||
<button id="btn">Export</button>
|
||||
</div>
|
||||
<div id="preview"></div>
|
||||
|
||||
<script type="module" src="./main.js"></script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ var opts = {
|
|||
contextWidth: 300,
|
||||
contextHeight: 200,
|
||||
devicePixelRatio: 4,
|
||||
}
|
||||
};
|
||||
|
||||
// var config = {
|
||||
// elementWrapper: {
|
||||
// controllerSize: 4,
|
||||
|
|
@ -29,3 +30,16 @@ const idraw = new iDraw(
|
|||
}
|
||||
);
|
||||
idraw.setData(data);
|
||||
|
||||
|
||||
|
||||
const btn = document.querySelector('#btn');
|
||||
btn.addEventListener('click', () => {
|
||||
idraw.exportDataURL({type: "image/png"}).then((dataURL) => {
|
||||
const preview = document.querySelector('#preview');
|
||||
preview.innerHTML = `<img width="300" src="${dataURL}">`;
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const { Image } = window;
|
|||
export function loadImage(src: string): Promise<HTMLImageElement> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image;
|
||||
img.setAttribute('crossOrigin', 'anonymous');
|
||||
img.onload = function() {
|
||||
resolve(img);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue