Giter Site home page Giter Site logo

oslllo / potrace Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 5.0 3.23 MB

A "1:1 output" JavaScript port of Potrace JS for NodeJS.

License: GNU General Public License v2.0

JavaScript 100.00%
potrace potrace-js potrace-port curve curve-optimization javascript-port nodejs

potrace's Introduction

Potrace

CI/Test npm

A "1:1 output" JavaScript port of Potrace JS for NodeJS.


Original image Potrace output
Original Image Potrace Output

Online Demo


Why did I create this package โ“

The issue


Prerequisites

  • Node.js v10+

Installation

npm install oslllo-potrace

Basic Usage


Taken from Example.js


Example 1

const path = require("path");
const Potrace = require("..");
const fs = require("fs-extra");
const Svg2 = require("oslllo-svg2");

async function example1() {
    var source = path.resolve("example/tree.jpg");
    var destination = path.resolve("example/tree.svg");
    var traced = await Potrace(source).trace();
    fs.writeFileSync(destination, traced);
    await Svg2(traced).png().extend(10).toFile("example/tree.png");
}

example1().then(() => {
    console.log("done");
}).catch((err) => {
    throw err;
});

Example 2

const path = require("path");
const Potrace = require("..");
const fs = require("fs-extra");
const Svg2 = require("oslllo-svg2");

async function example2() {
    var source = path.resolve("example/tree.jpg");
    var destination = path.resolve("example/tree.svg");
    var instance = Potrace(source);
    var traced = await instance.trace();
    fs.writeFileSync(destination, traced);
    await Svg2(traced).png().extend(10).toFile("example/tree.png");
}

example2().then(() => {
    console.log("done");
}).catch((err) => {
    throw err;
});

Parameters

  • source (String | Buffer): path to image to trace.
  • options (Object): option parameter object.
    • turnpolicy (string): how to resolve ambiguities in path decomposition. available options are [ Potrace.TURNPOLICY_BLACK, Potrace.TURNPOLICY_WHITE, Potrace.TURNPOLICY_LEFT, Potrace.TURNPOLICY_RIGHT, Potrace.TURNPOLICY_MINORITY, Potrace.TURNPOLICY_MAJORITY ] (default: Potrace.TURNPOLICY_MINORITY).
    • turdsize: (Number) suppress speckles of up to this size (default: 2).
    • optcurve: (Boolean) turn on/off curve optimization (default: true).
    • alphamax: (Number) corner threshold parameter (default: 1).
    • opttolerance: (Number) curve optimization tolerance (default: 0.2).
    • svgSize: (Number) set svg output size. NOTE: The resulting image size = the original image size * size (default: 1).
    • opt_type: (String) output svg type, available options are [curve]

Changelog

Please see CHANGELOG for more information what has changed recently.

Test

npm test

Credits

Potrace JS Port by @kilobtye.

Original Potrace by Peter Selinger.

Another Potrace Port For Node.js maintained by @tooolbox.

License

The GNU General Public License v2.0 (GPL-2.0). Please see License File for more information.

potrace's People

Contributors

dependabot-preview[bot] avatar ghustavh97 avatar github-actions[bot] avatar opengg avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.