Skip to content

Commit

Permalink
Switch to a javascript based port of potrace.
Browse files Browse the repository at this point in the history
WIP: this is super slow?

This is nice because it means people don't have to install a native
dependency to try things out. Unfortunately, potrace in javascript looks
like a bit of a mess:

- There's an unmaintained port from 4 years ago:
  https://github.com/kilobtye/potrace
- There's a fork of that which is NodeJS compatible, "with some
  additions": https://github.com/Iwasawafag/node-potrace
- There's this fork of *that* which some additional commits, I can't
  figure out what it's relationship to the `Iwasawafag` fork is:
  https://github.com/tooolbox/node-potrace/.
  (tooolbox/node-potrace#13)
- Unfortunately, one or more of the "additions" in the `Iwasawafag` and
  `toolbox` forks introduce issues with generating fonts, which there's
  yet another fork designed to fix. See
  tooolbox/node-potrace#7 and
  https://github.com/oslllo/potrace/.

So, I've introduced a dependency on the `oslllo` fork of a fork of a
fork of a fork. 😱
  • Loading branch information
jfly committed Oct 23, 2020
1 parent df02df5 commit dc8f559
Show file tree
Hide file tree
Showing 5 changed files with 1,214 additions and 27 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ cache:
- node_modules
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y potrace
script:
# Unfortunately, `npm audit` is failing, and it doesn't look like there's any easy fix.
# See https://github.com/cubing/icons/issues/55
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
We use the excellent [gulp-iconfont](https://www.npmjs.com/package/gulp-iconfont).

- `npm install`
- Install [potrace](http://potrace.sourceforge.net/).
- `npm run build` or `npm run watch` - Open `www/index.html` in your web browser.

## Releasing
Expand Down
36 changes: 11 additions & 25 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var del = require('del');
var gulp = require('gulp');
var path = require('path');
var jimp = require('gulp-jimp');
var Potrace = require('oslllo-potrace');
var through = require('through2');
var rename = require('gulp-rename');
var svg2png = require('gulp-svg2png');
Expand Down Expand Up @@ -132,30 +133,15 @@ function fontCssPipe() {

function bmp2svg() {
return through.obj(function(file, enc, next) {

var potraceProcess = child_process.spawn(
'potrace', ['-o', '-', '-b', 'svg'], {
stdio: [ 'pipe', 'pipe', 'inherit' ]
}
);

potraceProcess.stdin.write(file.contents);
potraceProcess.stdin.end();

// TODO - there must be some way of avoiding this...
var buffer = new Buffer.alloc(0);
potraceProcess.stdout.on('data', function(data) {
buffer = Buffer.concat([ buffer, data ]);
});

potraceProcess.once('close', function(code) {
if(code !== 0) {
next(new Error("potrace exited with code " + code, null));
} else {
file.extname = ".svg";
file.contents = buffer;
next(null, file);
}
});
const start = Date.now();
console.log(`starting trace of ${file.history}`); // <<< >>>
Potrace(file.contents).trace().then((traced) => {
const end = Date.now();
console.log(`finished trace of ${file.history}... took ${end-start} ms`); // <<< >>>
file.extname = ".svg";
var buffer = Buffer.from(traced, 'utf-8');
file.contents = buffer;
next(null, file);
}).catch(err => next(new Error(err)));
});
}
Loading

0 comments on commit dc8f559

Please sign in to comment.