01 May 2013 - After the site upgrade, all passwords were reset and you will need to ask the site for a login reset on your first connection.

GtkImage

This example shows how to use the GtkImage widget to display an image file in a window.

Loading a local file

<?php
error_reporting
(E_ALL);

/**
* Replace 'php-gtk.gif' by the name of a file
* in the same directory as the script
*/
$file = 'php-gtk.gif';

// standard stuff for window creation
$wnd = new GtkWindow();
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));
$wnd->set_position(Gtk::WIN_POS_CENTER);

/**
* You can use either the simple
* or advanced methods below
* to load the file, but not both
*/
# simple usage: you can load the image directly
# $img = GtkImage::new_from_file($file);

# more advanced usage: use a pixbuf
$pixbuf = GdkPixbuf::new_from_file($file);
$img = new GtkImage();
$img->set_from_pixbuf($pixbuf);

# add the image to the window and we're done
$wnd->add($img);
$wnd->show_all();
Gtk::main();
?>

Loading a remote file

In the simple case of a local file, there was not much interest in loading the file using the GdkPixbuf methods, because the file would alway be available. However, with remote files, we must import the files using the GdkPixbuf so we can ultimately check for errors in the load process.

Note that such remote loading needs GD, so we check for it immediately.

<?php
error_reporting
(E_ALL);

/**
* Replace 'php-gtk.gif' by the name of a file
* in the same directory as the script
*/
$file = 'http://gtk.php.net/gifs/php-gtk.gif';

if (!
function_exists("gd_info"))
  die(
'This code needs the GD extension to load remote GIFs');

// standard stuff for window creation
$wnd = new GtkWindow();
$wnd->connect_simple('destroy', array('Gtk', 'main_quit'));
$wnd->set_position(Gtk::WIN_POS_CENTER);

/**
* You can use either the simple
* or advanced methods below
* to load the file, but not both
*/
$gif = imagecreatefromgif($file);
$pixbuf = GdkPixbuf::new_from_gd($gif);
$img = new GtkImage();
$img->set_from_pixbuf($pixbuf);

# add the image to the window and we're done
$wnd->add($img);
$wnd->show_all();
Gtk::main();
?>