forked from kilobtye/potrace
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,442 additions
and
1,320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
jspm_packages | ||
node_modules | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.