This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 将网络图片转换为base64url | |
function convertImgToBase64(url, callback, outputFormat){ | |
var canvas = document.createElement('canvas'), | |
ctx = canvas.getContext('2d'), | |
img = new Image; | |
img.crossOrigin = 'Anonymous';//它开启了本地的跨域允许。当然服务器存储那边也要开放相应的权限才行,如果是设置了防盗链的图片在服务端就没有相应的权限的话你本地端开启了权限也是没有用的 | |
img.onload = function(){ | |
canvas.height = img.height; | |
canvas.width = img.width; | |
ctx.drawImage(img,0,0); |