#!/usr/bin/perl use strict; use warnings; use Gtk2 '-init'; use GD; use GD::Text::Align; my $time= localtime; my $image = new GD::Image(200,30); my $black = $image->colorAllocate(0,0,0); my $white = $image->colorAllocate(255,255,255); my $text = new GD::Text::Align( $image, font => gdLargeFont, # font => './arial.ttf', text => $time, color => $white, valign => "center", halign => "center", ); # the order of these two lines is important $image->filledRectangle( 15, 15, 150, 150, $black ); $text->draw(100,15); my $gdimage; open( IMAGE, ">",\$gdimage) || die "$!\n"; binmode( IMAGE ); print IMAGE $image->png(); close IMAGE; #gtk2 stuff my $mw = Gtk2::Window->new; my $vp = Gtk2::Viewport->new(undef, undef); $mw->add($vp); &load_image; $mw->signal_connect('destroy', sub { Gtk2->main_quit }); Gtk2->main; ########################################################### sub load_image { my $loader = Gtk2::Gdk::PixbufLoader->new; $loader->write ($gdimage); $loader->close; my $pixbuf = $loader->get_pixbuf; my $image = Gtk2::Image->new_from_pixbuf ($pixbuf); # my $pb = $image->get_pixbuf; # my ($x, $y) = ($pb->get_width, $pb->get_height); # $mw->set_title("dim ${x}x${y}"); $vp->add($image); $mw->show_all(); }