Glazy/svg2Image

★ 0Forks 0GitHub ↗Compare

README

svg2Image

Makes downloading SVGs as raster graphics images a breeze.

svg2Image(SVGElement, options).then(base64result)

Install

npm i @ferdipret/svg-2-img
# or
yarn add @ferdipret/svg-2-img

Features

  • Written in typescript.
  • Supports multiple image formats(png, jpeg, jpg).
  • Alter download image styles.
  • Returns the resulting base64 string as a promise.

Example

...
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>
    </>
  )
}

Issues