在 CasperJS 中使用 "captureSelector" 的 DOM 元素屏幕截图的质量

Quality of the DOM element screenshot using "captureSelector" in CasperJS

我正在使用 casperJS to try to get a screenshot of a DOM element using captureSelector, but the quality of the screenshot is really poor, but when capturing full screenshot using capture 它工作正常,质量正确。

谁能帮我解决这个问题?提前致谢。

CasperJS 脚本

var casper = require("casper").create({
  verbose: true,
  logLevel: 'debug',
  pageSettings: {
    loadImages: true,
    loadPlugins: false,
  }
});
// ***************************************************
var viewport_width = 1524;
var viewport_height = 768;
var ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"; 
var filename = "./screenshot_"+new Date().getTime() + "_" + viewport_width + "x" + viewport_height + "_desktop.jpg";
var url = "http://url-here.com";
var lang_header = "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3";
// ***************************************************
casper.on('remote.message', function(msg) {
  this.log('Remote message caught: ' + msg, "error");
});
casper.on("page.error", function(msg, trace) {
  this.log("Page Error: " + msg, "error");
});
casper.on('load.finished', function (status) {
  if (status !== 'success') {
    this.log("Failed to load page", "error");
  }
  else {
    this.log("The page has been loaded", "info");
  }
});
casper.start();
casper.thenOpen(url, function() {
  this.userAgent(ua);
  this.viewport(viewport_width, viewport_height).then(function() {
    this.wait(5000, function() {
      this.waitForSelector('#dom-element-id', function() {
        this.captureSelector(filename, '#dom-element-id', { quality: 100 });
      });
    });
  });
});
casper.run();

即使使用质量 imgOptions 参数,我得到的屏幕截图质量也很差。

this.captureSelector(filename, '#dom-element-id', { quality: 100 });

PhantomJS:版本 1.9.7

CasperJS:版本 1.0.2

PD:我没有放真实的网址,因为是一个内部项目。抱歉给您带来不便。

我已经更新了版本,现在可以使用了:

PhantomJS:版本 1.9.8

CasperJS:版本 1.1.0-beta3

感谢您的帮助:)