forked from renanbastos93/image-to-base64
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.js
More file actions
21 lines (19 loc) · 757 Bytes
/
Copy pathbrowser.js
File metadata and controls
21 lines (19 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';
(function(escope) {
function base64ToBrowser(buffer) {
return window.btoa([].slice.call(new Uint8Array(buffer)).map(function(bin) { return String.fromCharCode(bin); }).join(''));
}
function imageToBase64Browser(urlOrImage, param) {
if (!('fetch' in window && 'Promise' in window)) {
return Promise.reject('[*] It\'s image2base64 not compatible with your browser.');
}
return fetch(urlOrImage, param || {}).then(function(response) {
return response.arrayBuffer();
}).then(base64ToBrowser);
}
if (typeof module !== 'undefined') {
module.exports = imageToBase64Browser;
} else {
escope.imageToBase64 = imageToBase64Browser;
}
})(this);