You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
#!/usr/bin/env phantomjs
|
|
|
|
var system = require('system');
|
|
|
|
if (system.args.length < 3) {
|
|
console.log("usage: " + system.args[0] + " <url> <filename.png>");
|
|
phantom.exit(1);
|
|
}
|
|
|
|
var url = system.args[1];
|
|
var filename = system.args[2];
|
|
var page = require('webpage').create();
|
|
|
|
page.viewportSize = { width: 9999, height: 9999 };
|
|
page.zoomFactor = 2;
|
|
|
|
page.onError = function(msg, trace) {
|
|
console.log('Script error: ' + msg);
|
|
phantom.exit(1);
|
|
}
|
|
|
|
page.onResourceError = function(resourceError) {
|
|
console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
|
|
console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
|
|
phantom.exit(1);
|
|
};
|
|
|
|
page.open(url, function(status) {
|
|
if (status !== "success") {
|
|
console.log("Failed to load " + url);
|
|
phantom.exit(1);
|
|
}
|
|
|
|
var size = page.evaluate(function() {
|
|
// Alternative to zoomFactor:
|
|
//
|
|
// /* 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%";
|
|
//
|
|
// It has small issue with letter spacing though.
|
|
|
|
var term = $('.asciinema-player');
|
|
return [term.width(), term.height()];
|
|
});
|
|
|
|
if (!size[0]) {
|
|
console.log("Couldn't get dimensions of the player");
|
|
phantom.exit(1);
|
|
return;
|
|
}
|
|
|
|
page.clipRect = { left: 0, top: 0, width: size[0] * 2, height: size[1] * 2 };
|
|
page.render(filename, { format: 'png' });
|
|
phantom.exit(0);
|
|
});
|
|
|
|
// vim: ft=javascript
|