Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • SVGSaver

Index

Constructors

  • new SVGSaver(svg?: SVGSVGElement): SVGSaver
  • Converts and saves an SVG element as a PNG or SVG image.

    example
    const saver = new SVGSaver(document.getElementById('svg'));
    await saver.saveAsPNG('image.png'); // asynchronous

    console.log('saved image with data URL: ', saver.getSVGDataURL());

    Parameters

    • Optional svg: SVGSVGElement

      The SVG to be converted/saved.

    Returns SVGSaver

Properties

svg: SVGSVGElement

Methods

  • getPNGBlob(): Promise<Blob>
  • Gets the PNG Blob of the SVG.

    async

    Returns a promise that resolves with the PNG Blob.

    Returns Promise<Blob>

  • getPNGDataURL(): Promise<string>
  • Gets the PNG dataURL of the SVG.

    async

    Returns a promise that resolves with the PNG data URL.

    Returns Promise<string>

  • getSVGBlob(): Blob
  • Returns the SVG, after cleaning, as a text/xml Blob.

    Returns Blob

    SVG as a text/xml Blob.

  • getSVGDataURL(): string
  • Returns the SVG, after cleaning, as a image/svg+xml;base64 encoded dataURL string.

    Returns string

    SVG as image/svg+xml;base64 encoded dataURL string.

  • loadNewSVG(svg: SVGSVGElement): void
  • Load a different SVG.

    Parameters

    • svg: SVGSVGElement

      New SVG to load.

    Returns void

  • saveAsPNG(filename?: string): Promise<void>
  • Saves the SVG as a PNG file.

    async

    Parameters

    • Optional filename: string

      The name of the file to save, defaults to the SVG title or untitled.png.

    Returns Promise<void>

  • saveAsSVG(filename?: string): void
  • Saves the SVG as a .svg file.

    Parameters

    • Optional filename: string

      The name of the file to save, defaults to the SVG title or untitled.svg.

    Returns void

Generated using TypeDoc