RaspberryPiを使ってcui上でウェブページのスクリーンショットを撮りたいと思い、phantomjsを導入しようとした時に色々手こずったのでログとして残す
通常、phantomjsを導入するのにはかなり時間(2時間ぐらい)かかるらしい
はじめは時間が掛かる方法でやっていたが、やってられなくなりRaspberryPi用に作っている人がいないか調べたらでてきた
GitHub - aeberhardo/phantomjs-linux-armv6l: PhantomJS compiled on a Raspberry PI (Raspbian "wheezy").
github.com
導入方法
$ cd /tmp
$ wget http://github.com/aeberhardo/phantomjs-linux-armv6l/archive/master.zip
$ unzip master.zip
$ cd phantomjs-linux-armv6l-master
$ bunzip2 *.bz2 && tar xf *.tar
$ sudo chmod 755 phantomjs-1.9.0-linux-armv6l/bin/phantomjs
$ sudo mv /tmp/phantomjs-linux-armv6l-master/phantomjs-1.9.0-linux-armv6l/bin/phantomjs /usr/local/bin/
$ rm /tmp/master.zip
$ rm -r /tmp/phantomjs-linux-armv6l-master
#日本語フォントを導入
$ sudo apt-get install fonts-ipafont
インストールできているか確認
$ ./phantomjs-1.9.0-linux-armv6l/bin/phantomjs --version
1.9.0
これでCUI上でもWebのスクリーンショットを撮れるようになりました
参考程度でスクショするプログラム
var sample = require('webpage').create();
sample.open('http://google.com', function () {
window.setTimeout(function () {
page.render('hoge.png');
phantom.exit();
}, 200);
});
実行
phantomjs sample.js
参考
- GitHub http://github.com/aeberhardo/phantomjs-linux-armv6l
- Raspberry Pi2でPhantomJSをビルドする http://blog.mursts.jp/entry/2015/10/16/build-phantomjs-on-raspberrypi2/