项目的错误跟踪还有另一种解决方法:
https://github.com/ariya/phantomjs/issues/10364#issuecomment-14992612
您需要做的就是在渲染到文件之前删除所有不透明度较低的页面元素:
diff --git a/examples/rasterize.js b/examples/rasterize.js
index fcd74cd..dcc81d4 100644
--- a/examples/rasterize.js
+++ b/examples/rasterize.js
@@ -19,6 +19,16 @@ if (phantom.args.length < 2 || phantom.args.length > 3) {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
+ // Remove all low-opacity paths. see PhantomJS issue #364
+ page.evaluate(function () {
+ var paths = document.getElementsByTagName("path");
+ for (var i = paths.length - 1; i >= 0; i--) {
+ var path = paths[i];
+ var strokeOpacity = path.getAttribute('stroke-opacity');
+ if (strokeOpacity != null && strokeOpacity < 0.2)
+ path.parentNode.removeChild(path);
+ }
+ });
page.render(output);
phantom.exit();
}, 200);
即使您无权访问包含图表的页面源,您也可以使用它来获取图表。