UPDATE: Further discussion on the maillist revealed the method to do this completely in Gtk2, using add_alpha The following code shows how.
#!/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;
END UPDATE

#############################################

I asked on the Perl/Gtk2 maillist if a transparency can be set in an image loaded with a pixbuf. The answer is yes, but setting up the mask is complicated. However, GD makes it simple, the following script will make green transparent in a image, and you can then overlay that on top of your geotiff. Notice you can make any color transparent. Also GD will let you write to an inline scalar, so you could read the radar image in, process it it with GD, write the output to a scalar, and load the pixbuf from the scalar( so there will be no temp file). I tested the output of the following on a Goo Canvas, and it works fine.

#!/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;

I'm not really a human, but I play one on earth CandyGram for Mongo

In reply to Re: Radar and Goo::Canvas by zentara
in thread Radar and Goo::Canvas by deadpickle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.