-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to download icons as PNG files
- Loading branch information
1 parent
58a6e43
commit ea0ca88
Showing
5 changed files
with
110 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
export type Copy = 'svg'|'svg-path'|'name'|'markdown-preview'|'desktop-font-icon'|'codepoint'; | ||
export type Action = Copy|'download-svg'; | ||
export type Action = Copy|'download-svg'|'download-png'; |
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,17 @@ | ||
/** | ||
* Img helper | ||
*/ | ||
|
||
import {Canvg} from 'canvg'; | ||
|
||
export const svgToPng = async (svg: string, size = 512): Promise<string> => { | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = canvas.height = size; | ||
const ctx = canvas.getContext('2d'); | ||
if (ctx === null) { | ||
throw new Error(); | ||
} | ||
const v = await Canvg.fromString(ctx, svg); | ||
await v.render(); | ||
return canvas.toDataURL("image/png"); | ||
}; |
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