Makes downloading SVGs as raster graphics images a breeze.
svg2Image(SVGElement, options).then(base64result)npm i @ferdipret/svg-2-img
# or
yarn add @ferdipret/svg-2-img- Written in typescript.
- Supports multiple image formats(png, jpeg, jpg).
- Alter download image styles.
- Returns the resulting base64 string as a promise.
...
import svg2Img from '@ferdipret/svg-2-img'
function Component() {
const logoRef = useRef<SVGSVGElement>(null)
const handleClick = () => {
const svg = logoRef.current
svg2Img(svg)
}
return (
<>
<Logo ref={logoRef} />
<button onClick={handleClick}>Download image</button>
</>
)
}