Skip to content

Commit

Permalink
Get base64 (#146)
Browse files Browse the repository at this point in the history
* ajout fonctionn getDrawingBase64

* implem

* [Fix] retour type

* rename function getBase64

* finish rename

* doc
  • Loading branch information
Frédéric Llorca authored Mar 17, 2021
1 parent 08294f2 commit 81dddc4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ draw.download('svg')
draw.download('png')
draw.download('jpg')

// Get base64 string
draw.getBase64()

// Undo drawing.
draw.undo()

Expand Down
8 changes: 7 additions & 1 deletion src/useDrawing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface UseSvgDrawing {
changeCurve: (penwidth: DrawingOption['curve']) => void
getSvgXML: () => string | null
download: (ext: 'svg' | 'png' | 'jpg') => void
getBase64: () => string | undefined
}
export const useSvgDrawing = (
option?: Partial<DrawingOption>
Expand All @@ -27,6 +28,10 @@ export const useSvgDrawing = (
if (!drawingRef.current) return
drawingRef.current.download(ext)
}, [])
const getBase64 = useCallback(() => {
if (!drawingRef.current) return
return drawingRef.current.toBase64()
}, [])
const changePenColor = useCallback((param: DrawingOption['penColor']) => {
if (!drawingRef.current || !param) return
drawingRef.current.penColor = param
Expand Down Expand Up @@ -80,7 +85,8 @@ export const useSvgDrawing = (
clear,
undo,
getSvgXML,
download
download,
getBase64
}
]
}

0 comments on commit 81dddc4

Please sign in to comment.