Location: PHPKode > scripts > GtkMozEmbed Screenshot > GtkMozEmbedScreenshot.php
<?php

/**
 * GtkMozEmbedScreenshot
 *
 * @package GtkMozEmbedScreenshot
 * @author Daniel Anechitoaie
 * @copyright 2008
 * @license GPL
 * @version 0.1.0 Beta
 * @access public
 */
 
class GtkMozEmbedScreenshot
{
	var $version = '0.1.0';
	var $mozWidget;
	
	public function __construct()
	{
		if (!class_exists('Gtk')) 
		{ 
			die("Error: php-gtk2 module is not loaded!"); 
		}

		if (!class_exists('GtkMozEmbed'))
		{
			die("Error: your php-gtk2 module was not compiled with GtkMozEmbed support (--with-mozembed)!");
		}
	}
	
	public function take_screenshot($url, $fname)
	{
		$win = new GtkWindow();
		$this->mozWidget = new GtkMozEmbed();
		
		$win->set_size_request(800, 600);
		$win->add($this->mozWidget);

		$win->show_all();
		
		$this->mozWidget->connect_simple('net_stop' , array($this, 'save_image'), $fname);
		$win->connect_simple('destroy', array($this, 'quit'));

		$this->mozWidget->load_url($url);

		Gtk::main();
	}
	
	public function quit()
	{
        Gtk::main_quit();   // in a perfect world this should be enough 
                            // but due to a bug in php ( http://bugs.php.net/bug.php?id=39572 )
        exit;               // we must also call this little baby and by doing that we can only run this
                            // as a console app  
 	}
	
	public function save_image($fname)
	{
        list($x, $y, $width, $height, $depth) = $this->mozWidget->window->get_geometry();
        $pixbuf = new GdkPixbuf(Gdk::COLORSPACE_RGB, false, 8,  $width,  $height);
        $pixbuf->get_from_drawable($this->mozWidget->window, $this->mozWidget->get_colormap(), 0, 0, 0, 0,  $width,  $height);
        $pixbuf->save($fname, 'png');
        $this->quit();		
	}
}


$test = new GtkMozEmbedScreenshot();
$test->take_screenshot("http://www.youtube.com/", "test.png");

?>
Return current item: GtkMozEmbed Screenshot