#!/usr/bin/env ruby # # MozSnapshooter # Web site thumbnailer # # Copyright (C) 2005 Mirko Maischberger # Released in the Public Domain # # From an idea by Andrew McCall - # http://www.hackdiary.com/archives/000055.html require 'gtkmozembed' class MozSnapshooter < Gtk::Window def initialize super self.title="MozSnapshooter" self.border_width = 1 #self.resize(780, 570) #self.resize(1000, 1000) #self.resize(612,792) self.resize(1040,1331) 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.set_size_request(612,792) self.child.set_size_request(1040,1331) #self.child.set_size_request(1024,768) self.child.signal_connect("net_stop") { on_net_stop } #self.child.location = "http://yahoo.com/" 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(320, 200, Gdk::Pixbuf::INTERP_HYPER) #pixbuf.save("screenshot-thumb.png","png") pixbuf.save(ARGV[1],"png") puts "Wrote screenshot-thumb.png (",width,"x",height,")" Gtk.main_quit end end Gtk.init MozSnapshooter.new Gtk.main