Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function load image from canvas #3

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7ddca94
added load image from canvas function
casperlamboo Apr 20, 2016
74a2273
updated docs
casperlamboo Apr 20, 2016
87dc7fc
fix typo
casperlamboo Apr 20, 2016
7dd5972
install jspm
casperlamboo Feb 28, 2017
41be3bf
separate functions
casperlamboo Feb 28, 2017
636383d
add test
casperlamboo Feb 28, 2017
7b45b35
remove some util functions
casperlamboo Feb 28, 2017
596f693
clean up
casperlamboo Feb 28, 2017
66dc7b4
clean up
casperlamboo Feb 28, 2017
b22d7c7
clean up
casperlamboo Feb 28, 2017
b191242
clean up
casperlamboo Feb 28, 2017
34c7077
clean up
casperlamboo Feb 28, 2017
0f2caa0
clean up
casperlamboo Mar 1, 2017
b6fe98c
clean up
casperlamboo Mar 1, 2017
5502ae7
Add read me
casperlamboo Mar 1, 2017
1e5c8f4
remove potrace
casperlamboo Mar 1, 2017
c43dcb8
update package.json
casperlamboo Mar 1, 2017
d320cce
Merge branch 'test1'
casperlamboo Mar 1, 2017
e2a87aa
implement getPaths
casperlamboo Mar 1, 2017
73d7835
remove size argument
casperlamboo Mar 1, 2017
485ad8f
added size
casperlamboo Mar 1, 2017
3ad5c68
fix y-property in bezier path
casperlamboo Mar 1, 2017
f5c7675
version bumb
casperlamboo Mar 1, 2017
21e2259
update package.json
casperlamboo Mar 1, 2017
ba839fb
fix getPaths
casperlamboo Mar 1, 2017
dbe23db
Fix capital character in file name
casperlamboo Mar 2, 2017
1dcf54d
Fix capital character in file name
casperlamboo Mar 2, 2017
680f206
version bumb
casperlamboo Mar 2, 2017
69a9b2e
add trace bitmap
casperlamboo Mar 17, 2017
adfc3ee
bump version
casperlamboo Mar 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
110 changes: 106 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,110 @@
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.bitmap**

Traces a given bitmap.

```javascript
[...Path] = POTRACE.traceBitmap(bitmap: POTRACE.Bitmap, [ options: Object ])
```
- bitmap: bitmap containing image info (1 and 0 values)
- options: trace options


**POTRACE.getSVG**

Converts trace result to svg.

```javascript
svg: String = POTRACE.getSVG([...Path])
```

**POTRACE.getPaths**

Converts trace result to readable paths.

```javascript
svg: String = POTRACE.getPaths([...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: {}
});
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "potrace-js",
"version": "0.0.5",
"description": "Traces bitmap images to vector paths",
"main": "lib/index.js",
"jspm": {
"name": "potrace",
"main": "index.js",
"directories": {
"lib": "src"
},
"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": [
"es2015"
],
"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-es2015": "^6.22.0",
"jspm": "^0.17.0-beta.40"
}
}
Loading