All Projects → exupero → Savesvgaspng

exupero / Savesvgaspng

Licence: mit
Save SVGs as PNGs from the browser.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Savesvgaspng

Ikonograph
⚠️ This project is no longer mantained
Stars: ✭ 13 (-98.71%)
Mutual labels:  svg
Flowchart.js
Draws simple SVG flow chart diagrams from textual representation of the diagram
Stars: ✭ 7,711 (+668.03%)
Mutual labels:  svg
House
Proof of Concept and Research repository.
Stars: ✭ 37 (-96.31%)
Mutual labels:  svg
Respin
React SVG loading spinner based on jxnblk.com/loading
Stars: ✭ 21 (-97.91%)
Mutual labels:  svg
Built vector
Generate Flutter vector code from a subset of SVG files.
Stars: ✭ 33 (-96.71%)
Mutual labels:  svg
Svgr
Transform SVGs into React components 🦁
Stars: ✭ 8,263 (+723.01%)
Mutual labels:  svg
Librecms
Free Open Source Content Management System, based on PHP, Bootstrap and jQuery.
Stars: ✭ 12 (-98.8%)
Mutual labels:  svg
Svg To Component
Convert SVG to React/Vue components
Stars: ✭ 40 (-96.02%)
Mutual labels:  svg
Angled Edges
📐 Quickly create angled section edges using only Sass
Stars: ✭ 969 (-3.49%)
Mutual labels:  svg
Bpmn Js Examples
Some examples how to use bpmn-js
Stars: ✭ 981 (-2.29%)
Mutual labels:  svg
Ruby Gem Downloads Badge
Clean and simple gem downloads count badge, courtesy of http://shields.io/. You can checkout the application directly at the following URL:
Stars: ✭ 29 (-97.11%)
Mutual labels:  svg
Resvg
An SVG rendering library.
Stars: ✭ 964 (-3.98%)
Mutual labels:  svg
Logicflow
A front-end framework for process visualization.
Stars: ✭ 973 (-3.09%)
Mutual labels:  svg
Diagram Js
A toolbox for displaying and modifying diagrams on the web.
Stars: ✭ 881 (-12.25%)
Mutual labels:  svg
Onthefly
🔗 Generate TinySVG, HTML and CSS on the fly
Stars: ✭ 37 (-96.31%)
Mutual labels:  svg
Wechat
🔥 iOS 利用MVVM + RAC + ViewModel-Based Navigation来搭建微信(WeChat 7.0.0+)的整体基本架构,以及实现微信朋友圈、通讯录、下拉小程序、搜索等主要功能,代码规范惊为天人、注释详解令人发指、细节处理精益求精、核心功能配备文档、接近98%还原度的原生App视觉体验,代码不多,注释多。(持续更新,敬请期待,欢迎Star和Fork…)
Stars: ✭ 870 (-13.35%)
Mutual labels:  svg
Flag Icon Css
🎏 A curated collection of all country flags in SVG — plus the CSS for easier integration
Stars: ✭ 7,982 (+695.02%)
Mutual labels:  svg
Panzoom
Universal pan and zoom library (DOM, SVG, Custom)
Stars: ✭ 1,003 (-0.1%)
Mutual labels:  svg
Svg World Map
🗺 A JavaScript library to easily integrate one or more SVG world maps with all nations (countries) and second-level political subdivisions (countries, provinces, states).
Stars: ✭ 38 (-96.22%)
Mutual labels:  svg
Jquery Mapael
jQuery plugin based on raphael.js that allows you to display dynamic vector maps
Stars: ✭ 981 (-2.29%)
Mutual labels:  svg

saveSvgAsPng

Installation

npm install save-svg-as-png

Prerequisites

SaveSvgAsPng relies on JavaScript promises, so any browsers that don't natively support the standard Promise object will need to have a polyfill.

Usage

To save a PNG, include the script saveSvgAsPng.js in your page, then call the saveSvgAsPng function with an SVG node and a filename:

saveSvgAsPng(document.getElementById("diagram"), "diagram.png");

The filename is the preferred filename when saving the image to the file system. The browser may change the name of the file if there is already a file by that name in the target directory.

If you want to scale the image up or down, you can pass a scale factor in an options object:

saveSvgAsPng(document.getElementById("diagram"), "diagram.png", {scale: 0.5});

Other options are documented below.

If you just want a dataURI for an SVG, you can call svgAsDataUri, which returns a promise:

svgAsDataUri(document.getElementById("diagram"), options).then(uri => ...);

If you want a dataURI of a PNG generated from an SVG, you can call svgAsPngUri, which also returns a promise:

svgAsPngUri(document.getElementById("diagram"), options).then(uri => ...);

Compatible with browserify and requirejs.

If you want to use TypeScript, necessary type definitions are available in Typings public registry.

Options

  • backgroundColor — Creates a PNG with the given background color. Defaults to transparent.
  • canvg - If canvg is passed in, it will be used to write svg to canvas. This will allow support for Internet Explorer
  • encoderOptions - A Number between 0 and 1 indicating image quality. The default is 0.8
  • encoderType - A DOMString indicating the image format. The default type is image/png.
  • fonts - A list of {text, url, format} objects the specify what fonts to inline in the SVG. Omitting this option defaults to auto-detecting font rules.
  • height - Specify the image's height. Defaults to the viewbox's height if given, or the element's non-percentage height, or the element's bounding box's height, or the element's CSS height, or the computed style's height, or 0.
  • left - Specify the viewbox's left position. Defaults to 0.
  • modifyCss - A function that takes a CSS rule's selector and properties and returns a string of CSS. Supercedes selectorRemap and modifyStyle. Useful for modifying properties only for certain CSS selectors.
  • modifyStyle - A function that takes a CSS rule's properties and returns a string of CSS. Useful for modifying properties before they're inlined into the SVG.
  • scale — Changes the resolution of the output PNG. Defaults to 1, the same dimensions as the source SVG.
  • selectorRemap — A function that takes a CSS selector and produces its replacement in the CSS that's inlined into the SVG. Useful if your SVG style selectors are scoped by ancestor elements in your HTML document.
  • top - Specify the viewbox's top position. Defaults to 0.
  • width - Specify the image's width. Defaults to the viewbox's width if given, or the element's non-percentage width, or the element's bounding box's width, or the element's CSS width, or the computed style's width, or 0.
  • excludeUnusedCss - Exclude CSS rules that don't match any elements in the SVG.
  • excludeCss - Exclude all CSS rules

Testing

run tests with tape

npm test

Support

Chrome limits data URIs to 2MB, so you may have trouble generating PNGs beyod a certain size.

Internet Explorer will only work if canvg is passed in, otherwise it will throw a SecurityError when calling toDataURL on a canvas that's been written to. canvg may have it's own issues with SVG support, so make sure to test the output.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].