Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Perl/Tk problems with PNG transparence

by wmfs (Acolyte)
on Jul 30, 2014 at 12:50 UTC ( [id://1095610]=perlquestion: print w/replies, xml ) Need Help??

wmfs has asked for the wisdom of the Perl Monks concerning the following question:

Having created PNG images of playing cards and used GIMP to 'transparent' curved corners, I having problems with Perl/Tk failing to allow the background to be shown in these 'transparent' areas, instead I am seeing four white areas. There is now problem is displayed in HTML: (my HTML code is not showing correctly so for imgage please read img.)

<html> </p> <p> <body bgcolor="#E6E6FA"> </p> <p> <img src="Cards/00.png"> </p> <p> <img src="Cards/20.png"> </p> <p> <img src="Cards/50.png"> </p>
...... etc (see:- http://i.imgur.com/wlnHn6h.png) but the 'failing' code, of the form:
$Card_Back = $main->Photo( '-format' => 'png', -file => $dir . "Cards/00.png");
produces this type of display: http://i.imgur.com/6N13iKX.png Thanks for any help, Bill

Replies are listed 'Best First'.
Re: Perl/Tk problems with PNG transparence
by zentara (Archbishop) on Jul 30, 2014 at 13:03 UTC
    Tk itself, does not support transparency, but Tk::Zinc does. Another alternative is to move up to Gtk2 or Gtk3, which does handle transparency. For example see: Goo Canvas and transparent images
    #!/usr/bin/perl use warnings; use strict; use Tk::Zinc; my $width = 100; my $height = 100; my $mw = MainWindow->new(-background => 'cyan'); $mw->geometry($width.'x'.$height.'+300+300'); $mw->overrideredirect(1); my $zinc = $mw->Zinc(-width => $width, -height => $height, -reshape => 1, #clips zinc -fullreshape => 1, #clips $mw and xterm -backcolor => 'cyan', )->pack; #make a flower my $petal = $zinc->add('curve',1,[[$width/2,$height], [0,0, 'c'], [$width,0, 'c'], [$width/2,$height]], -tags => ['bezier1'], -filled => 1, -fillcolor => 'cyan', -closed => 1, -linewidth => 0, -priority => 1, -visible => 0, ); # using the triangulaire curve to reshape both TkZinc and Mainwindow w +idgets $zinc->itemconfigure(1, -clip => $petal); my $petal1 = $zinc->add('curve',1,[[$width/2,$height], [-2*$width,-100 +, 'c'], [3*$width,-100, 'c'], [$width/2,$hei +ght]], -tags => ['bezier1'], -filled => 1, -fillcolor => 'cyan', -closed => 1, -linewidth => 0, -priority => 1, -visible => 1, ); &Tk::MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Boy! That was quick! Unfortunately I'm having problems locating Tk::Zinc. It's not showing on PPM under ActivePerl, and CPAN Tk::Zinc doesn;t appear to find it either. The CPAN website lists http://www.tkzinc.org/ or http://freshmeat.net/projects/zincisnotcanvas/ as possible sources, but the first looks duff to me, and downloading from the second reports 'file not found'. Anyone know where I can find Tk::Zinc, please?

        I don't have ActivePerl or Tk modules installed on my system, but using the CPAN shell, I was able to download Tk::Zinc without any issues. Are you sure that you have cpan configured properly for you network (such as web/ftp proxies)?

        Also, if you use your web browser to go to Tk::Zinc, you can download the tarball to manually install it. Look for the link for tk-zinc-3.303.tar.gz in the upper right hand portion of the screen. Keep in mind that if you plan to download and manually install this module, you'll have to manually take care of any needed dependencies too.

Re: Perl/Tk problems with PNG transparence
by zentara (Archbishop) on Jul 30, 2014 at 18:55 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1095610]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-28 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found