PhantomJS - clipRect 屬性



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 的螢幕截圖。它將生成以下 輸出

Google Search
phantomjs_webpage_module_properties.htm
廣告
© . All rights reserved.