Skip to content

Commit

Permalink
feat(deps): Simplify dependencies, remove canvas/jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenGG committed Dec 31, 2021
1 parent a00c02a commit c013c58
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 2,311 deletions.
28 changes: 23 additions & 5 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
const path = require("path");
const Potrace = require("..");
const fs = require("fs-extra");
const Svg2 = require("oslllo-svg2");
const { svg2png, initialize } = require('svg2png-wasm');
const wasm = require.resolve('svg2png-wasm').replace(/(svg2png-wasm).*/, '$1/svg2png_wasm_bg.wasm')

const init = async () => {
const buffer = await fs.readFile(wasm)

await initialize(buffer)
}

let initPromise;

const draw = async (svg) => {
initPromise = initPromise || init()
await initPromise

return svg2png(svg)
}

async function example1() {
var source = path.resolve("example/tree.jpg");
var destination = path.resolve("example/tree.svg");
var traced = await Potrace(source).trace();
fs.writeFileSync(destination, traced);
await Svg2(traced).png().extend(10).toFile("example/tree.png");
await fs.outputFile(destination, traced);
const png = await draw(traced)
await fs.outputFile("example/tree.png", png);
}

async function example2() {
var source = path.resolve("example/tree.jpg");
var destination = path.resolve("example/tree.svg");
var instance = Potrace(source);
var traced = await instance.trace();
fs.writeFileSync(destination, traced);
await Svg2(traced).png().extend(10).toFile("example/tree.png");
await fs.outputFile(destination, traced);
const png = await draw(traced)
await fs.outputFile("example/tree.png", png);
}

module.exports = {
Expand Down
Binary file modified example/tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion example/tree.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c013c58

Please sign in to comment.