Giter VIP home page Giter VIP logo

esm-potrace-wasm's Introduction

ESM Potrace Wasm

A modern ESM build of the Potrace library for use in the browser.

Installation

npm install --save esm-potrace-wasm

Usage

import { potrace, init } from 'esm-potrace-wasm';

(async () => {
  // Initialize the module once.
  await init();

  /**
   * The `imageBitmapSource` parameter is an `ImageBitmapSource`, that is any of:
   * - `HTMLImageElement`
   * - `SVGImageElement`
   * - `HTMLVideoElement`
   * - `HTMLCanvasElement`
   * - `ImageData`
   * - `ImageBitmap`
   * - `Blob`
   */
  const svg = await potrace(
    imageBitmapSource,
    (options = {
      turdsize: 2,
      turnpolicy: 4,
      alphamax: 1,
      opticurve: 1,
      opttolerance: 0.2,
      pathonly: false,
      extractcolors: true,
      posterizelevel: 2, // [1, 255]
      posterizationalgorithm: 0, // 0: simple, 1: interpolation
    })
  );
})();

Developing

Modify src/potrace/ and run npm run build to update the ESM build in dist/. The emscripten build file is located at ./build.sh (or build.ps1 for Win32) respectively. A simple demo that imports dist/index.js is available in demo/ and can be started by running npm start.

Apps using this

This library is used in SVGcode.

SVGcode application screenshot

License

โš ๏ธ GPL-v2.0, due to the original Potrace license.

Acknowledgements

Based on @nturley's fork of @IguteChung's initial potrace-wasm. Unfortunately, the original author did not react on my Pull Request, so I forked.

esm-potrace-wasm's People

Contributors

beaufortfrancois avatar sylmroz avatar tomayac 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.