sourcegraph / go-webkit2

WebKit API bindings (WebKitGTK+ v2) for Go
https://sourcegraph.com/github.com/sourcegraph/go-webkit2
Other
313 stars 61 forks source link

How to set the size of a snapshot in GetSnapshot? #40

Open veqryn opened 6 years ago

veqryn commented 6 years ago

I am trying to take a snapshot of a WebView, but all my snapshots comes out at 320x5068. I would like to take a snapshot at 800x800, or at least a width of 800 pixels and I can crop it myself later.

I've tried SetSizeRequest and SetAllocation on the WebView. I've tried putting the WebView into a Window that has been SetDefaultSize and SetResizable=false.

Nothing seems to work. Please help me?

maitredede commented 4 years ago

Hi, In my case, I did this :

window, err := gtk.OffscreenWindowNew()
webView.SetSizeRequest(1920, 1080);
window.Add(webView)
// remaining code

The resulting image has width=1908, that can be explained by scrollbars appearing on the website I am viewing. To view the windows, you can "screenshot" it :

surface, err := window.GetSurface()
surface.WriteToPNG("/tmp/window.png")