-
-
Save simonw/63d398138b69d7f3bd6372a839a0d045 to your computer and use it in GitHub Desktop.
PhantomJS rasterize.js with "Retina" output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var system = require('system'); | |
var page = require('webpage').create(), | |
address, output, size; | |
if (system.args.length < 2 || system.args.length > 3) { | |
console.log('Usage: rasterize.js URL filename'); | |
phantom.exit(); | |
} else { | |
console.log(system.args); | |
address = system.args[1]; | |
output = system.args[2]; | |
page.viewportSize = { width: 1280, height: 1024 }; | |
page.open(address, function (status) { | |
if (status !== 'success') { | |
console.log('Unable to load the address!'); | |
} else { | |
page.evaluate(function () { | |
/* scale the whole body */ | |
document.body.style.webkitTransform = "scale(2)"; | |
document.body.style.webkitTransformOrigin = "0% 0%"; | |
/* fix the body width that overflows out of the viewport */ | |
document.body.style.width = "50%"; | |
}); | |
window.setTimeout(function () { | |
page.render(output); | |
phantom.exit(); | |
}, 200); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment