https://github.com/zillding/svg-to-url
A utility to convert svg file to data url string
https://github.com/zillding/svg-to-url
Last synced: 8 months ago
JSON representation
A utility to convert svg file to data url string
- Host: GitHub
- URL: https://github.com/zillding/svg-to-url
- Owner: zillding
- Created: 2017-06-30T10:20:04.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-05-27T23:51:48.000Z (about 2 years ago)
- Last Synced: 2024-05-28T09:02:32.355Z (about 2 years ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/svg-to-url
- Size: 660 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# svg-to-url
[]()
[](https://github.com/prettier/prettier)
A node utility to convert svg to svgo optimized data url
Powered by [svgo](https://github.com/svg/svgo)
## Installation
`npm install -g svg-to-url`
## Usage
### Use from command line
```sh
$ cat path/to/circle.svg
$ svg-to-url path/to/circle.svg
data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='100' width='100'%3E%3Ccircle cx='50' cy='50' r='40' stroke='%23000' stroke-width='3' fill='red'/%3E%3C/svg%3E
Copied to clipboard!
```
### Use as a node module
```js
import svgToUrl from "svg-to-url";
const result = await svgToUrl("path/to/circle.svg");
console.log(result);
// data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='100' width='100'%3E%3Ccircle cx='50' cy='50' r='40' stroke='%23000' stroke-width='3' fill='red'/%3E%3C/svg%3E
```
If only the svg string processor is needed, there is another api exposed.
```js
import { stringToUrl } from "svg-to-url";
// optional custom svgo config: https://github.com/svg/svgo
const svgoConfig = {
plugins: [...]
};
const getUrlFromSvgString = stringToUrl(svgoConfig);
const resultUrl = getUrlFromSvgString("...");
```