qrohlf / trianglify

Algorithmically generated triangle art
http://qrohlf.com/trianglify/
GNU General Public License v3.0
10.08k stars 669 forks source link

Error with newer versions of canvas: Object.render_png #109

Closed hayesall closed 5 years ago

hayesall commented 5 years ago

Summary

I did a fresh install of cairo + canvas + trianglify on MacOS, then ran into an error with render_png.

This might be an issue with changes in the 2.0 release of canvas, since installing canvas@1.6.13 instead of canvas@2.5.0 seemed to resolve it.

Steps to Reproduce

The examples/save-as-png.js should be enough to reproduce this.

Error Trace ```javascript /Users/hayesall/Desktop/example/node_modules/trianglify/lib/pattern.js:54 ctx.canvas.width = opts.width; ^ TypeError: Cannot read property 'canvas' of undefined at render_canvas (/Users/hayesall/Desktop/example/node_modules/trianglify/lib/pattern.js:54:9) at Object.render_png [as png] (/Users/hayesall/Desktop/example/node_modules/trianglify/lib/pattern.js:74:12) at Object. (/Users/hayesall/Desktop/example/save-as-png.js:15:9) at Module._compile (internal/modules/cjs/loader.js:816:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10) at Module.load (internal/modules/cjs/loader.js:685:32) at Function.Module._load (internal/modules/cjs/loader.js:620:12) at Function.Module.runMain (internal/modules/cjs/loader.js:877:12) at internal/main/run_main_module.js:21:11 ```

Short-term solution

Setting a hard dependency to canvas@1.6.13 might be suitable to resolving this. The following seems to resolve this error:

$ brew install cairo
$ export PKG_CONFIG_PATH="/Users/hayesall/homebrew/opt/libffi/lib/pkgconfig"
$ npm install canvas@1.6.13
$ npm install trianglify
qrohlf commented 5 years ago

This will be resolved in the next build, which drops support for canvas 1.x and adds support for 2.5.0. If you want to live dangerously, you can install the alpha:

yarn add trianglify@next
# or
npm install --save trianglify@next