Skip to content

Instantly share code, notes, and snippets.

@nhunzaker
Created October 23, 2012 19:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhunzaker/3941030 to your computer and use it in GitHub Desktop.
Save nhunzaker/3941030 to your computer and use it in GitHub Desktop.
Viewports in Phantom.js
// Viewport
//
// phantom.js viewport.js http://google.com 400
var args = require("system").args;
var url = args[1];
var width = args[2];
var height = args[3];
if (!url || !width) {
console.log("Usage: [url] [width] [height]");
phantom.exit();
}
var page = require("webpage").create();
page.viewportSize.width = width;
if (height) {
page.viewportSize.height = height;
}
page.open(url, function() {
var label = url.match(/http\:\/\/(.*(\?.*|))/)[1].replace(/\//g, ".");
page.render([label, width, height || "x", "png"].join("."));
console.log("Done");
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment