Phantom JS - 剪辑矩形 - Javascript 帮助
我正在使用 phantom js 对页面进行屏幕截图
http://code.google。 com/p/phantomjs/wiki/QuickStart#Rendering
它有一个名为clipRect的功能
http://code.google.com/p/phantomjs/wiki/Interface#clipRect_(object)
有人可以告诉我如何将以下代码修改为我们的clipRect,这样我只得到部分截图而不是全部?
if (phantom.state.length === 0) {
if (phantom.args.length !== 2) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
var address = phantom.args[0];
phantom.state = 'rasterize';
phantom.viewportSize = { width: 600, height: 600 };
phantom.open(address);
}
} else {
var output = phantom.args[1];
phantom.sleep(200);
phantom.render(output);
phantom.exit();
}
i'm using phantom js to screen shot a page
http://code.google.com/p/phantomjs/wiki/QuickStart#Rendering
it has a feature called clipRect
http://code.google.com/p/phantomjs/wiki/Interface#clipRect_(object)
can someone show me how i would modify the following code to us clipRect so i only get a partial screenshot and not the whole thing?
if (phantom.state.length === 0) {
if (phantom.args.length !== 2) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
var address = phantom.args[0];
phantom.state = 'rasterize';
phantom.viewportSize = { width: 600, height: 600 };
phantom.open(address);
}
} else {
var output = phantom.args[1];
phantom.sleep(200);
phantom.render(output);
phantom.exit();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您尝试获取特定元素的屏幕截图,您可以根据 这篇文章:
If you are trying to get a screenshot of a particular element, you could get the necessary information for
clipRect
fromgetBoundingClientRect
as per the bottom of this article:来自精细手册:
因此,请尝试在调用
render< 之前设置
clipRect
/code>:您必须弄清楚左上角(
top
和left
)在哪里以及有多大(width
和height
)您想要的剪切矩形。您可以在调用
render()
之前的任何时间设置clipRect
,但从这里开始,看看会发生什么。From the fine manual:
So try setting
clipRect
right before you callrender
:You'd have to figure out where the upper left corner (
top
andleft
) is and how big (width
andheight
) you want the clipping rectangle to be.You can probably set the
clipRect
any time beforerender()
is called but start with that and see what happens.发生的事情是我正在使用brew并且它正在安装v 1.0.0,其中clipRect和几乎所有其他功能不受支持,因为v 1.0.0是最旧的版本。
如果您按照以下说明操作:http://code.google.com/p/phantomjs /wiki/BuildInstructions#Mac_OS_X
然后右键单击已编译的文件并单击显示/查看内容(在 mac 上),然后将可执行文件 bin/phantomjs.app/Contents/MacOS/phantomjs 复制到某个位置PATH 中的目录。
请随时在这里发帖,我正在监控此事,如果需要我可以提供帮助。
What was happening is i was using brew and it was installing v 1.0.0 where clipRect and almost every other function wasn't supported as v 1.0.0 is the oldest version.
If you follow these instructions: http://code.google.com/p/phantomjs/wiki/BuildInstructions#Mac_OS_X
then right click on the complied file and click show/view contents (on mac) then copy the executable bin/phantomjs.app/Contents/MacOS/phantomjs to some directory in your PATH.
Feel free to post on here i'm monitoring this and i can help if needed.