Skip to content

Instantly share code, notes, and snippets.

@myokoym
Created March 28, 2014 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myokoym/9834466 to your computer and use it in GitHub Desktop.
Save myokoym/9834466 to your computer and use it in GitHub Desktop.
Ruby/WebKitGTK2でWebページのスクリーンショットを取得する例。引数にURLを指定して、sキーで取得。
#!/usr/bin/env ruby
require "webkit-gtk2"
uri = ARGV[0]
window = Gtk::Window.new
window.signal_connect("destroy") do
Gtk.main_quit
end
web_view = WebKitGtk2::WebView.new
web_view.load_uri(uri)
window.add(web_view)
window.signal_connect("key-press-event") do |widget, event|
case event.keyval
when Gdk::Keyval::GDK_KEY_s
x, y, width, height, depth = window.window.geometry
pixbuf = Gdk::Pixbuf.from_drawable(nil,
window.window,
0, 0,
width, height)
pixbuf.save("screenshot-#{Time.now.strftime("%Y%m%d%H%M%S")}.png", "png")
end
end
window.show_all
Gtk.main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment