Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Last active October 13, 2020 19:35
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 ljmotta/85a5fb23b829be5fb4d0f16075f3fbe0 to your computer and use it in GitHub Desktop.
Save ljmotta/85a5fb23b829be5fb4d0f16075f3fbe0 to your computer and use it in GitHub Desktop.
Base64Png Editor GetContent/SetContent/GetPreview
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