Skip to content

Commit

Permalink
Use PhantomJS instead of webkit2png
Browse files Browse the repository at this point in the history
So that the Linux lovers on the team can get some of the action.
  • Loading branch information
Paul M Furley committed Jan 6, 2016
1 parent d61842f commit 243bd39
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions phantom-screenshot.js
Original file line number Diff line number Diff line change
@@ -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] + ' <some URL> <width in pixels>');
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();
});
5 changes: 4 additions & 1 deletion prototype2pdf
Original file line number Diff line number Diff line change
@@ -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" ]
Expand All @@ -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:-
Expand Down

0 comments on commit 243bd39

Please sign in to comment.