如何在Phantomjs中缩放屏幕截图以包含网页的整个内容?换句话说,如何动态计算所需的宽度和高度,以便屏幕截图包含所有网页的内容?我目前的代码是流星部署。
电流控制器:
var system = require('system');
// Web Address (URL) of the page to capture
var url = system.args[1];
// File name of the captured image
var file = system.args[2];
var size = system.args[3].split('*') || {};
//var fileName = system.args[4];
var page = require('webpage').create();
var width = parseInt(size[0], 10);
var height = parseInt(size[1], 10);
page.viewportSize = { width: width, height : height};
page.clipRect = { top: 260, left: 0, width: width, height: height };
console.log('size: ');
console.log(page.viewportSize.width);
console.log(page.viewportSize.height);
// Set the User Agent String
page.settings.userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5";
// Render the screenshot image
page.open ( url, function ( status ) {
if ( status !== "success") {
console.log("Could not open web page : " + url);
phantom.exit();
} else {
window.setTimeout ( function() {
page.render(file);
console.log("Download the screenshot : " + file);
phantom.exit();
}, 1000);
}
});
当前快照命令:
var sizeObj = {width: 2048, height: 1024};
var sizeStr = sizeObj.width + '*' + sizeObj.height;
var child_process = Meteor.npmRequire('child_process'),
url = App.GlobalSettings.root + 'dashboard?savedView=' + viewId,
user = Meteor.users.findOne({username: App.const.USERS_SYSTEM_NAME}),
fullFileName = screenShotRoot + fileName;
var command = child_process.spawn('phantomjs',
[
process.env.PWD + '/server/controllers/.screenshot-phantom.js',
url,
fullFileName,
sizeStr
]);