Node.jsでCanvasが使えるようになるnode-canvasを入れる
Node.jsで画像を加工したくなったのでライブラリを探したところ、サーバーサイドでCanvasを使えるようにするnode-canvasというライブラリが良さそうだったので入れてみました。
依存ライブラリでCairoが必要らしいので先に入れる
$ brew install cairo
node-canvasを入れる
$ npm install canvas
gyp: Call to './util/has_cairo_freetype.sh' returned exit status 0. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/Cellar/node/0.10.20/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 12.5.0
gyp ERR! command "node" "/usr/local/Cellar/node/0.10.20/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/hentai-kun/node/sandbox/node_modules/canvas
gyp ERR! node -v v0.10.20
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0
エラーが出た。
fontconfig
というものが必要らしい。
依存ライブラリのFontconfigを入れる
$ brew install fontconfig
node-canvasを入れる(リトライ)
$ npm install canvas
Package 'xcb-shm', required by 'cairo', not found
gyp: Call to './util/has_cairo_freetype.sh' returned exit status 0. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/Cellar/node/0.10.20/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 12.5.0
gyp ERR! command "node" "/usr/local/Cellar/node/0.10.20/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/hentai-kun/node/sandbox/node_modules/canvas
gyp ERR! node -v v0.10.20
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0
またしてもエラー。
今度はxcb-shm
というものが必要らしい。
惰性でxcb-shmを入れる
$ brew install xcb-shm
Error: No available formula for xcb-shm
そんなものはないらしい…
ここまでやって、初めてドキュメントを読む
ちゃんと書いてありました。
If you see "Package 'xcb-shm', required by 'cairo', not found", you probably installed Cairo with homebrew and need to do this: $ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/X11/lib/pkgconfig
node-canvasを入れる(今度こそ)
$ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/X11/lib/pkgconfig
$ npm install canvas
今度は入りました。
使ってみる
と思っていたのですが、入れている間に別の方法でもっと簡単な解決策を思いついてしまったので、試していないままここで終わる。