#!/usr/bin/perl -w use strict; use warnings; use Goo::Canvas; use Gtk2 '-init'; use Glib qw(TRUE FALSE); my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_default_size(640, 600); my $swin = Gtk2::ScrolledWindow->new; $swin->set_shadow_type('in'); $window->add($swin); my $canvas = Goo::Canvas->new(); $canvas->set_size_request(600, 450); $canvas->set_bounds(0, 0, 1000, 1000); $swin->add($canvas); my $root = $canvas->get_root_item(); # base file my $im = Gtk2::Gdk::Pixbuf->new_from_file("MI.png"); my $w = $im->get_width; my $h = $im->get_height; my $image = Goo::Canvas::Image->new( $root, $im, 0, 0, 'width' => $w, 'height' => $h); # overlay file which needs transparency added my $im1 = Gtk2::Gdk::Pixbuf->new_from_file("zzrgbwb.png"); my $im2 = $im1->add_alpha(1,0 ,255 , 0); # returns a new pixbuf # makes green transparent # use 0..255 for color levels, NOT hex my $w1 = $im2->get_width; my $h1 = $im2->get_height; my $image1 = Goo::Canvas::Image->new( $root, $im2, 50, 50, 'width' => $w, 'height' => $h); $window->show_all(); Gtk2->main; #### #!/usr/bin/perl use warnings; use strict; use GD; GD::Image->trueColor(1); my $img_file = 'zzrgbwb.png'; my $gd = GD::Image->new($img_file) or die; my ($w, $h) = $gd->getBounds(); print "$w $h\n"; # allocate some colors my $white = $gd->colorAllocate(255,255,255); my $black = $gd->colorAllocate(0,0,0); my $red = $gd->colorAllocate(255,0,0); my $green = $gd->colorAllocate(0,255,0); my $blue = $gd->colorAllocate(0,0,255); # make the background transparent and interlaced $gd->transparent($green); #$gd->interlaced('true'); open(GD, ">zzrgbwb-gt.png") or die; binmode GD; print GD $gd->png; close GD;