Skip to content

Commit

Permalink
Merge branch 'test1'
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Mar 1, 2017
2 parents 87dc7fc + c43dcb8 commit d320cce
Show file tree
Hide file tree
Showing 19 changed files with 1,442 additions and 1,320 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

jspm_packages
node_modules
lib
91 changes: 87 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,91 @@
potrace
=======
# POTRACE
Based on http://potrace.sourceforge.net and https://github.com/kilobtye/potrace.

A javascript port of [Potrace](http://potrace.sourceforge.net)
Converts bitmap images to vector paths.

[online demo](http://kilobtye.github.io/potrace/)
# Usage

### Using JSPM (ECMAScript / ES6 Module)

Install the library.

```
jspm install POTRACE=github:casperlamboo/POTRACE
```

Include the library.

```javascript
import POTRACE from 'POTRACE';
```

### Using NPM (CommonJS module)

Install the library.

```
npm install potrace-js
```

Include the library.

```javascript
var POTRACE = require('potrace-js');
```

# API

**Options**

```javascript
{
turnpolicy: enum('black' | 'white' | 'left' | 'right' | 'minority' | 'majority'),
turdsize: Float,
optcurve: Bool,
alphamax: Float,
opttolerance: Float
}
```
- turnpolicy: how to resolve ambiguities in path decomposition. (default: "minority")
- turdsize: suppress speckles of up to this size (default: 2)
- optcurve: turn on/off curve optimization (default: true)
- alphamax: corner threshold parameter (default: 1)
- opttolerance: curve optimization tolerance (default: 0.2)

**POTRACE.traceUrl**

Traces a given image from url.

```javascript
[...Path] = async POTRACE.traceUrl(url: String, [ options: Object ])
```
- url: path to the image
- options: trace options

**POTRACE.traceImage**

Traces a given image.

```javascript
[...Path] = POTRACE.traceImage(image: HTMLImageElement, [ options: Object ])
```
- image: image containing the image
- options: trace options

**POTRACE.traceCanvas**

Traces a given canvas.

```javascript
[...Path] = POTRACE.traceCanvas(canvas: HTMLCanvasElement, [ options: Object ])
```
- canvas: canvas containing the image
- options: trace options

**POTRACE.getSVG**

Converts trace result to svg.

```javascript
svg: String = POTRACE.getSVG([...Path])
```
22 changes: 22 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">

<title>Potrace</title>

<script type="text/javascript" src="/jspm_packages/system.src.js"></script>
<script type="text/javascript" src="/jspm.config.js"></script>

</head>
<body>

<div id="container"></div>

<script type="text/javascript">
System.import('./index.js');
</script>

</body>
</html>
5 changes: 5 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as POTRACE from 'src/index.js';

POTRACE.traceUrl('test.png')
.then(paths => POTRACE.getSVG(paths, 1.0, 'curve'))
.then(svg => document.write(svg));
Binary file added example/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions jspm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
SystemJS.config({
paths: {
"npm:": "jspm_packages/npm/",
"potrace/": "src/"
},
browserConfig: {
"baseURL": "/"
},
devConfig: {
"map": {
"plugin-babel": "npm:[email protected]"
}
},
transpiler: "plugin-babel",
packages: {
"potrace": {
"main": "potrace.js",
"meta": {
"*.js": {
"loader": "plugin-babel"
}
}
}
}
});

SystemJS.config({
packageConfigPaths: [
"npm:@*/*.json",
"npm:*.json"
],
map: {},
packages: {}
});
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "potrace-js",
"version": "0.0.1",
"description": "Traces bitmap images to vector paths",
"main": "lib/index.js",
"jspm": {
"name": "potrace",
"main": "potrace.js",
"devDependencies": {
"plugin-babel": "npm:systemjs-plugin-babel@^0.0.21"
}
},
"scripts": {
"prepublish": "npm run build",
"build": "babel src --out-dir lib",
"test": "echo \"Error: no test specified\" && exit 1"
},
"babel": {
"presets": [
"es2017"
],
"plugins": [
"add-module-exports"
]
},
"format": "esm",
"repository": {
"type": "git",
"url": "git+https://github.com/casperlamboo/potrace.git"
},
"author": "Casper Lamboo",
"license": "ISC",
"bugs": {
"url": "https://github.com/casperlamboo/potrace/issues"
},
"homepage": "https://github.com/casperlamboo/potrace#readme",
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2017": "^6.22.0",
"jspm": "^0.17.0-beta.40"
}
}
Loading

0 comments on commit d320cce

Please sign in to comment.