Giter VIP home page Giter VIP logo

svgutils's Introduction

svgutils

Svg Utils for pasing SVGFile and manipulate Matrix object like Snap.svg

npm status build status dependency status Code Climate experimental Flattr this git repo

Install

npm install svgutils

Requirements

NodeJS

Required version : 0.10.22

Usage

With SVGUtils you can :

  • Convert SVG Document to JSON
  • Convert JSON to SVG Document
  • Manipulate Svg
  • Use Matrix to SVG or elements
  • ...

Warning

For Text and Group, the boundingbox result is not true but it's enough for basic manipulations

Loading SVG file

var Svg = require('svgutils').Svg;


Svg.fromSvgDocument(__dirname + '/test2.svg', function(err, svg){
    // ...
});

Convert SVG file to JSON

var Svg = require('svgutils').Svg;

Svg.fromSvgDocument(__dirname + '/test2.svg', function(err, svg){
    if(err){
        throw new Error('SVG file not found or invalid');
    }

    var json = svg.toJSON();
});

Apply Matrix and get transformed svg

Currents Matrix only

var Svg = require('svgutils').Svg;

Svg.fromSvgDocument(__dirname + '/test2.svg', function(err, svg){
    if(err){
        throw new Error('SVG file not found or invalid');
    }

    svg.applyMatrix(null, function(newSvg){
        console.log(newSvg.toString());
    });
});

Externals and currents Matrix

var Svg     = require('svgutils').Svg,
    Matrix  = require('svgutils';.Matrix;

Svg.fromSvgDocument(__dirname + '/test2.svg', function(err, svg){
    if(err){
        throw new Error('SVG file not found or invalid');
    }

    // Ex : apply translate(10, 20) to all svg
    svg.applyMatrix(new Matrix(1, 0, 0, 1, 10, 20), function(newSvg){
        console.log(newSvg.toString());
    });
});

Save generated SVG or Convert to PNG

Save SVG

var Svg     = require('svgutils').Svg,
    Matrix  = require('svgutils';.Matrix;

Svg.fromSvgDocument(__dirname + '/test2.svg', function(err, svg){
    if(err){
        throw new Error('SVG file not found or invalid');
    }

    svg.save({ output : '/home/user/svg.svg' }, function(err, filename){
        if(err){
            throw err;
        }
    });
});

Save PNG

var Svg     = require('svgutils').Svg,
    Matrix  = require('svgutils';.Matrix;

Svg.fromSvgDocument(__dirname + '/test2.svg', function(err, svg){
    if(err){
        throw new Error('SVG file not found or invalid');
    }

    svg.savePng({ output : '/home/user/svg.png' }, function(err, filename){
        if(err){
            throw err;
        }
    });
});

Convert others formats to SVG

DXF to SVG (thanks to Thomas Desmoulin and his DXF-parsing module)

You can create SVG from DXF file. You can, as you want, get specifics DXF layers.

Svg.fromDxfFile({
    path : __dirname + '/test.dxf'
}, function (err, svg) {
    if(err){
        throw new Error('SVG file not found or invalid');
    }
    
    // your converted svg
});

Contrbute

  • Fork the repo
  • create a branch git checkout -b my_branch
  • Add your changes
  • Commit your changes: git commit -am "Added some awesome stuff"
  • Push your branch: git push origin my_branch
  • Make a pull request to development branch

svgutils's People

Contributors

throrin19 avatar bitdeli-chef avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.