Phantomjs-cliprect-property

提供:Dev Guides
移動先:案内検索

PhantomJS-clipRectプロパティ

clipRectは、値がtop、left、width、heightのオブジェクトで、* render()*メソッドによって使用される場合、Webページの画像キャプチャを取得するために使用されます。 clipRectが定義されていない場合は、renderメソッドが呼び出されたときに完全なWebページのスクリーンショットを撮ります。

構文

その構文は次のとおりです-

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 サイトのスクリーンショットを撮ります。 次の output が生成されます-

Google検索