LoginSignup
2
4

More than 5 years have passed since last update.

DOM要素のスクリーンショットを撮る(2)pageres

Posted at

DOM要素のスクリーンショットを撮る(DOM要素を画像に変換する)には幾つかの方法があるようですが、html2canvasはダメだったので、次にpageresを試してみました。

npm install

npm install pageresします。

コード

DOM要素のスクリーンショットを撮る(1)html2canvasで作成したHTMLドキュメントのスクリーンショットを撮ってみることにしました。

  new pageres({ format: 'jpg' })
    .src('http://localhost:3000/asset/test/test.html', ['1280x1024'], { selector: '.fitch' })
    .dest(__dirname)
    .run();

使ってみる

実際に使ってみます。

DOM要素のスクリーンショットを撮る(1)html2canvasで作成したHTMLドキュメントをブラウザで表示すると下のようになります。

fm11.jpg

そして、上のコードを実行すると、プログラムが格納されているフォルダにlocalhost!3000!asset!test!test.html-1280x1024.jpgという名称のJPEGファイルが生成されました。

このJPEGファイルは下のようなものでした。

fm13.jpg

正しくスクリーンショットが撮れていることが分かります!

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4