0

when i take screenshots using phanomjs using the following code works fine and I am getting width as 1920px and height is not a problem for me.

var webPage = require('webpage');
var page = webPage.create();

page.viewportSize = { width: 1920, height: 1080 };
page.open("http://www.google.com", function start(status) {
page.render('google_home.png');
 phantom.exit();

but, when i set the dimension as

page.viewportSize = { width: 320, height: 780 };

the resulting image width is 602px.

how to set width for taking screenshot using page.render() function?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Mohan Kumar
  • 621
  • 1
  • 8
  • 25

2 Answers2

0

If the minimum page width (or fixed width) is bigger than the viewport size, then PhantomJS will render a screenshot that has the same width as the page (body).

You can of course crop the screenshot by setting the corresponding dimension and position using page.clipRect.

You can also experiment with the zoomFactor.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
0

Actually I can't. because "http://www.google.com" forcefully set the minimum width of the document above some 600px. so, when i call page.render() it renders the complete document which is having a width not 320px.

Mohan Kumar
  • 621
  • 1
  • 8
  • 25