We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
url =>base64
let urlToBase64 = url => new Promise((resolve, reject) => { let image = new Image(); image.onload = function() { let canvas = document.createElement("canvas"); canvas.width = this.naturalWidth; canvas.height = this.naturalHeight; canvas.getContext("2d").drawImage(image, 0, 0); let ret = canvas.toDataURL("image/png"); resolve(ret); }; image.setAttribute("crossOrigin", "Anonymous"); image.src = url; image.onerror = e => { reject(e); }; });
base64 => blob
let base2Blob = ({ b64data = "", contentType = "", sliceSize = 512 } = {},filename) => new Promise((resolve, reject) => { let byteChars = atob(b64data); let byteArrays = []; for (let offset = 0; offset < byteChars.length; offset += sliceSize) { let slice = byteChars.slice(offset, offset + sliceSize); let byteNumbers = []; for (let i = 0; i < slice.length; i++) { byteNumbers.push(slice.charCodeAt(i)); } byteArrays.push(new Uint8Array(byteNumbers)); } let ret = new Blob(byteArrays, { type: contentType }); ret = Object.assign(ret, { preview : URL.createObjectURL(ret); name: `${filename}.png` }) });
blob =>base64
let blob2Base64 = (blob) => new Promise((resolve, reject) => { const fileReader = new FileReader(); fileReader.onload = (e) => { resolve(e.target.result); } fileReader.readAsDataURL(blob); fileReader.onerror = (e) => { reject(e); } });
The text was updated successfully, but these errors were encountered:
No branches or pull requests
url =>base64
base64 => blob
blob =>base64
The text was updated successfully, but these errors were encountered: