Skip to content

Instantly share code, notes, and snippets.

@jefBinomed
Created December 3, 2020 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefBinomed/657d4e38d566985b996337ba84c08641 to your computer and use it in GitHub Desktop.
Save jefBinomed/657d4e38d566985b996337ba84c08641 to your computer and use it in GitHub Desktop.
2020-fugu-image-trick
export function prepareImage(img) {
return new Promise((resolve) => {
fetch(img.src)
.then((response) => response.blob())
.then((blob) => {
var reader = new FileReader();
reader.onload = function () {
img.src = this.result;
resolve();
}; // <--- `this.result` contains a base64 data URI
reader.readAsDataURL(blob);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment