Skip to content

Instantly share code, notes, and snippets.

@chmeee
Created August 1, 2009 19:13
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 chmeee/159778 to your computer and use it in GitHub Desktop.
Save chmeee/159778 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# MozSnapshooter
# Web site thumbnailer
#
# Copyright (C) 2005 Mirko Maischberger
# Released in the Public Domain
#
# From an idea by Andrew McCall - <andrew@textux.com>
# http://www.hackdiary.com/archives/000055.html
require 'rubygems'
require 'gtkmozembed'
class MozSnapshooter < Gtk::Window
def initialize
super
self.title="MozSnapshooter"
self.border_width = 1
self.resize(780, 570)
Gtk::MozEmbed.set_profile_path(ENV['HOME'] + '.mozilla', 'RubyGecko')
self << Gtk::MozEmbed.new
self.child.chrome_mask = Gtk::MozEmbed::ALLCHROME
self.child.set_size_request(816,600)
self.child.signal_connect("net_stop") { on_net_stop }
self.child.location = ARGV[0]
@countdown = 2
# The user is bored, let's quit.
self.signal_connect("destroy") do
$stderr.print "closing...\n"
Gtk.main_quit
end
self.show_all
end
def on_net_stop
Gtk::timeout_add(1000) do
@countdown -= 1
if(@countdown > 0)
puts @countdown
true
else
screenshot
false
end
end
end
def screenshot
gdkw = self.child.parent_window
x, y, width, height, depth = gdkw.geometry
width -= 16
pixbuf = Gdk::Pixbuf.from_drawable(nil, gdkw, 0, 0, width, height)
pixbuf = pixbuf.scale(800, 640, Gdk::Pixbuf::INTERP_HYPER)
pixbuf.save("screenshot-thumb.png","png")
puts "Wrote screenshot-thumb.png"
Gtk.main_quit
end
end
Gtk.init
MozSnapshooter.new
Gtk.main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment