<?php

error_reporting(E_ALL);

if ($argc < 2)
	die("\nUsage: php -q gdk_pixbuf.php <imagefile>\n\n");

$image_file = $argv[1];

$window = new GtkWindow();
$window->set_border_width(5);
$window->set_title('GdkPixbuf example');
$window->set_resizable(false);
$window->connect_object('destroy', array('gtk', 'main_quit'));

try {
	$pixbuf = GdkPixbuf::new_from_file($image_file);
} catch (PhpGtkGErrorException $e) {
	die($e->message . "\n");
}

$area = new GtkDrawingArea();
$area->set_size_request($pixbuf->get_width(), $pixbuf->get_height());
$frame = new GtkFrame();
$frame->add($area);
$frame->set_shadow_type(Gtk::SHADOW_IN);
$window->add($frame);

$layout = $window->create_pango_layout(basename($image_file) . 
									   "\n\xd0\x90\xd0\xbd\xd0\xb4\xd1\x80\xd0\xb5\xd0\xb9");
$fontdesc = new PangoFontDescription('Arial,Helvetica 14');
$layout->set_font_description($fontdesc);
list(, $extents) = $layout->get_pixel_extents();

$area->connect('expose_event', 'expose_event', $pixbuf, $layout, $extents);

$window->show_all();

gtk::main();

function expose_event($area, $event, $pixbuf, $layout, $extents)
{
	$area->window->draw_pixbuf($area->style->fg_gc[Gtk::STATE_NORMAL],
							   $pixbuf,
							   $event->area->x, $event->area->y,
							   $event->area->x, $event->area->y);


	if ($event->area->x < $extents[0] + 3 &&
		$event->area->y < $extents[1] + 3) {
		$area->window->draw_layout($area->style->white_gc, 3, 3, $layout);
		$area->window->draw_layout($area->style->black_gc, 2, 2, $layout);
	}
}

?>
