-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for background image
- Loading branch information
1 parent
ea85775
commit 685b568
Showing
5 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Inspired by https://stackoverflow.com/a/58569300/829505 | ||
export function createDataUrl(blob: Blob) { | ||
return new Promise(function(resolve, reject) { | ||
const reader = new FileReader(); | ||
|
||
reader.onloadend = function() { | ||
resolve(reader.result); | ||
}; | ||
|
||
reader.onerror = function() { | ||
reject() | ||
} | ||
|
||
reader.readAsDataURL(blob); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Use this function to fetch a url and convert in into a Blob. Useful when you want to set a background image to your editor. | ||
* @example | ||
* const blob = await urlToBlob(url) | ||
* | ||
*/ | ||
export async function urlToBlob(url: string) { | ||
return fetch(url).then(res => res.blob()) | ||
} |