Skip to content

Instantly share code, notes, and snippets.

View Leptune's full-sized avatar
💭
I may be slow to respond.

常乐 Leptune

💭
I may be slow to respond.
View GitHub Profile
@Leptune
Leptune / convertImgToBase64.js
Last active January 25, 2019 06:45
前端js通用函数
// 将网络图片转换为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);