https://github.com/iwstkhr/svg-to-png
A library to convert svg to png (base64)
https://github.com/iwstkhr/svg-to-png
png svg
Last synced: 5 months ago
JSON representation
A library to convert svg to png (base64)
- Host: GitHub
- URL: https://github.com/iwstkhr/svg-to-png
- Owner: iwstkhr
- License: mit
- Created: 2022-04-02T09:30:40.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-31T16:07:18.000Z (9 months ago)
- Last Synced: 2024-11-09T20:44:10.601Z (7 months ago)
- Topics: png, svg
- Language: JavaScript
- Homepage:
- Size: 360 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# svg-to-png
A library to convert svg to png (base64)## Install
```
npm install https://github.com/iwstkhr/svg-to-png.git
```## Usage
### HTML
Copy `main.js` to your app js directory.
```
cp node_modules/@iwstkhr/svg-to-png/dist/main.js $YOUR_APP_JS_PATH
``````html
TitleSVG
PNG (Base64)
![]()
Base64
svgToPngLib.svgToPng(document.querySelector('#svg')).subscribe(function (value) {
document.querySelector('#png').setAttribute('src', value);
document.querySelector('#base64').innerHTML = value;
});```
### TypeScript
```typescript
import { svgToPng } from '@iwstkhr/svg-to-png';const svg = document.querySelector('#svg') as SVGSVGElement;
svgToPng(svg).subscribe(value => console.info(value));
```## License
MIT