Skip to content

Commit

Permalink
supports delay and browser width
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkeller committed Oct 23, 2013
1 parent c1d1e5f commit cfad8e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "depict",
"version": "0.1.0",
"version": "0.1.1",
"author": {
"name": "Kevin Schaul",
"email": "kevin.schaul@gmail.com",
Expand All @@ -16,6 +16,7 @@
"preferGlobal": true,
"dependencies": {
"optimist": "~0.6.0",
"phantom": "~0.5.2"
"phantom": "~0.5.2",
"sleep": "~1.1.1"
}
}
16 changes: 16 additions & 0 deletions src/depict.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var child_process = require('child_process');
var fs = require('fs');
var optimist = require('optimist');
var phantom = require('phantom');
var sleep = require('sleep');

var argv = optimist
.usage('Usage: depict URL OUT_FILE [OPTIONS]')
Expand All @@ -27,6 +28,16 @@ var argv = optimist
describe: 'Hide attributes of this selector berore rendering.',
default: false
})
.options('w', {
alias: 'browser-width',
describe: 'Specify the desired browser width.',
default: 1440
})
.options('d', {
alias: 'delay',
describe: 'Specify a delay time, in seconds.',
default: 5
})
.check(function(argv) {
if (argv._.length !== 2) throw new Error('URL and OUT_FILE must be given.');
})
Expand Down Expand Up @@ -54,6 +65,9 @@ if (hide_selector) {
css_text += "\n\n " + hide_selector + " { display: none; }\n";
}

var viewport_width = argv.w || argv['browser-width'];
var delay_time = argv.d || argv['delay'];

function depict(url, out_file, selector, css_text) {
// phantomjs heavily relies on callback functions

Expand All @@ -73,6 +87,7 @@ function depict(url, out_file, selector, css_text) {
page = _page;
page.set('onError', function() { return; });
page.open(url, prepForRender);
page.set('viewportSize', {width: viewport_width, height: 900});
}

function prepForRender(status) {
Expand All @@ -91,6 +106,7 @@ function depict(url, out_file, selector, css_text) {
}

function renderImage(rect) {
sleep.sleep(delay_time);
page.set('clipRect', rect);
page.render(out_file, cleanup);
}
Expand Down

0 comments on commit cfad8e1

Please sign in to comment.