viewport - Dynamically change viewportSize in PhantomJS -


in order have phantomjs create screenshots of page @ different viewport widths, i'd adjust dynamically. not work, though:

var system = require('system'); var page = require('webpage').create();  page.viewportsize = { width: 800, height: 600 };  page.open('http://example.com', function (status) {      page.render('medium.png');      page.viewportsize = { width: 630, height: 420 };      page.render('small.png');      phantom.exit(); }); 

when run phantomjs script.js produces 2 identical png files medium.png , small.png @ width of 800px each. expected behaviour have medium.png , small.png @ width of 630px. how can achieved?

ps: this answer similar question produces error me. the accepted answer question suggests quite ugly workaround avoid.

i think should possible set viewport size , open page again this:

var system = require('system'); var page = require('webpage').create();  page.viewportsize = { width: 800, height: 600 };  page.open('http://example.com', function (status) {      page.render('medium.png');       page.viewportsize = { width: 630, height: 420 };      page.open('http://example.com', function (status) {          page.render('small.png');          phantom.exit();     }); }); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -