From 243bd3998971836848c0fcbf277db552cb3f8b01 Mon Sep 17 00:00:00 2001 From: Paul M Furley Date: Thu, 3 Dec 2015 17:10:32 +0000 Subject: [PATCH] Use PhantomJS instead of `webkit2png` So that the Linux lovers on the team can get some of the action. --- README.md | 12 +++++++++--- phantom-screenshot.js | 26 ++++++++++++++++++++++++++ prototype2pdf | 5 ++++- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100755 phantom-screenshot.js diff --git a/README.md b/README.md index 2edf6c3..bf340c2 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,19 @@ prototype2pdf is a command line tool that takes a list of URLs for a prototype a ## Dependencies -- [webkit2png](http://www.paulhammond.org/webkit2png/) +- [PhantomJS](http://phantomjs.org/) - [ImageMagick](http://www.imagemagick.org) -Both can be installed using [Homebrew](http://brew.sh): +On Mac OS X, this can be installed via [Homebrew](http://brew.sh): ``` -brew install webkit2png imagemagick +brew install phantomjs +``` + +On debian-type systems, this can be installed via apt: + +``` +sudo apt-get install phantomjs ``` ## Usage diff --git a/phantom-screenshot.js b/phantom-screenshot.js new file mode 100755 index 0000000..c2fb048 --- /dev/null +++ b/phantom-screenshot.js @@ -0,0 +1,26 @@ +#!/usr/bin/env phantomjs + + +var page = require('webpage').create(), + system = require('system'), + address; + +if (system.args.length != 3) { + console.log('Usage: ' + system.args[0] + ' '); + phantom.exit(); +} + +page.viewportSize = { + width: system.args[2], + height: 768 +}; + +address = system.args[1]; +page.open(address, function(status) { + if (status !== 'success') { + console.log('FAIL to load the address'); + } else { + page.render(address.replace(/[^a-z0-9]/gi, '_').toLowerCase() + '.png'); + } + phantom.exit(); +}); diff --git a/prototype2pdf b/prototype2pdf index 39b50de..8cbb6d6 100755 --- a/prototype2pdf +++ b/prototype2pdf @@ -1,5 +1,8 @@ #!/bin/bash +THIS_SCRIPT=$0 +THIS_DIR=$(dirname "${THIS_SCRIPT}") + # check if there are already PNGs here, and bail if there are ls *.png > /dev/null 2>&1 if [ "$?" -eq "0" ] @@ -9,7 +12,7 @@ then fi while read url; do - webkit2png --fullsize --scale=1 --width=${1:-320} --clipwidth=1 $url > /dev/null + ${THIS_DIR}/phantom-screenshot.js $url ${1:-320} > /dev/null done convert *.png +repage -crop 1090x1603 +repage -units PixelsPerInch -density 150x150 -extent 1090x1603 -bordercolor transparent -border 75x75 pdf:-