前端根据图片url下载图片到本地的一种方法
废话不多说直接上代码
var canvas = document.createElement('canvas');
var img = new Image();
img.crossOrigin = 'anonymous';
img.onerror = function () {
eturn reject(new Error('找不到 ' + href));
};
img.onload = function () {
canvas.width = img.width;
canvas.height = img.height;
canvas.getContext('2d').drawImage(img, 0, 0);
svgToPng(canvas.toDataURL('image/png'))
};
img.src = href;
上一篇
下一篇