wch / webshot

Take screenshots of web pages from R
http://wch.github.io/webshot/
228 stars 40 forks source link

add option for better render resolution ( code included) #26

Closed giko45 closed 7 years ago

giko45 commented 8 years ago

Hi, To get a better resolution in renderd images I usually change in the webshot.js file (system.file("webshot.js", package="webshot"))

the follwoing line casper.start(url).viewport(opts.vwidth, opts.vheight); to casper.start(url).viewport(opts.vwidth, opts.vheight).zoom(2);

Could that be added as a option instead?

wch commented 7 years ago

Sounds like a good idea. It would also be nice to do HiDPI (Retina-resolution) screenshots (i.e. with a window.devicePixelRatio) which could differ from a zoomed screenshot because a page may load different, higher-res images when it thinks it's rendering on a HiDPI device.

giko45 commented 7 years ago

Hi,

I checked the code you checked and noticed that you also changed the viewport. I only did use casper.start(url).viewport(opts.vwidth, opts.vheight).zoom(2) without changeing the viewport.

Wy is the change in viewport needed. Does that not lead to changed fontsizes etc?

wch commented 7 years ago

Maybe we have a different understanding of what the zoom is supposed to do, but without changing the viewport, the "virtual" viewport size changes when you zoom, so the end result can have a very different layout.

For example, here's the R homepage taken with no zoom: r-normal

Here it is with zoom=2, but no changing of the viewport. The pixel dimensions are the same but the layout changes: r-small-zoomed-no-viewport

Here it is with zoom=2 and a doubling of the viewport (you may need to open this in a new window to see how it differs from the first image: r-small-zoomed