PhantomJS clipRect 区域截屏属性详解


发布日期 : 2024-03-18 11:49:46 UTC

访问量: 10 次浏览

PhantomJS clipRect 属性

clipRect 是一个包含 top、left、width 和 height 值的对象,用于在使用 render() 方法时对网页进行图像捕获。如果未定义 clipRect,则在调用 render 方法时将对整个网页进行截屏。

语法

clipRect 语法如下:

var page = require('webpage').create();
page.clipRect = {
top: 14,
left: 3,
width: 400,
height: 300
};

示例

看下面的示例来理解 clipRect 属性的使用。

var wpage = require('webpage').create();
wpage.viewportSize = {
width: 1024,
height: 768
};
wpage.clipRect = {
top: 0,
left: 0,
width: 500,
height: 500
};
//the clipRect is the portion of the page you are taking a screenshot
wpage.open('http://www.google.com/', function() {
wpage.render('e.png');
phantom.exit();
});

在这里,我们正在对网站进行截图 google.com 。它将生成以下输出

PhantomJS clipRect 属性