Last active
October 13, 2020 19:35
-
-
Save ljmotta/85a5fb23b829be5fb4d0f16075f3fbe0 to your computer and use it in GitHub Desktop.
Base64Png Editor GetContent/SetContent/GetPreview
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
const getContent = useCallback(() => { | |
return editorContent; | |
}, [editorContent]); | |
const setContent = useCallback((path: string, content: string) => { | |
setOriginalContent(content); | |
}, []); | |
const getPreview = useCallback(() => { | |
const width = imageRef.current!.width; | |
const height = imageRef.current!.height; | |
return ` | |
<svg version="1.1" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" | |
xmlns="http://www.w3.org/2000/svg" | |
xmlns:xlink="http://www.w3.org/1999/xlink"> | |
<image width="${width}" height="${height}" xlink:href="data:image/png;base64,${editorContent}" /> | |
</svg>`; | |
}, [editorContent]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment